#194745: preventing NPE in MakeStatic.
1.1 --- a/javahints/nbproject/project.properties Tue Jan 25 09:50:02 2011 +0100
1.2 +++ b/javahints/nbproject/project.properties Mon Jan 31 15:42:25 2011 +0100
1.3 @@ -50,7 +50,7 @@
1.4 auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-limit-width=80
1.5 javac.compilerargs=-Xlint:unchecked
1.6 javac.source=1.5
1.7 -spec.version.base=2.40.0
1.8 +spec.version.base=2.41.0
1.9
1.10 nbm.needs.restart=true
1.11 requires.nb.javac=true
2.1 --- a/javahints/src/org/netbeans/modules/javahints/MakeStatic.java Tue Jan 25 09:50:02 2011 +0100
2.2 +++ b/javahints/src/org/netbeans/modules/javahints/MakeStatic.java Mon Jan 31 15:42:25 2011 +0100
2.3 @@ -88,6 +88,11 @@
2.4 //strange, but:
2.5 return null;
2.6 }
2.7 +
2.8 + if (el.getModifiers().contains(Modifier.ABSTRACT)) {
2.9 + //strange, but:
2.10 + return null;
2.11 + }
2.12
2.13 TreePath source = info.getTrees().getPath(el);
2.14
2.15 @@ -121,9 +126,15 @@
2.16 boolean safe;
2.17
2.18 try {
2.19 + safe = true;
2.20 switch (source.getLeaf().getKind()) {
2.21 case METHOD:
2.22 - s.scan(new TreePath(treePath, ((MethodTree) source.getLeaf()).getBody()), null);
2.23 + MethodTree method = (MethodTree) source.getLeaf();
2.24 +
2.25 + if (method.getBody() != null) {
2.26 + s.scan(new TreePath(treePath, method.getBody()), null);
2.27 + }
2.28 +
2.29 break;
2.30 case VARIABLE:
2.31 ExpressionTree initializer = ((VariableTree) source.getLeaf()).getInitializer();
2.32 @@ -132,7 +143,6 @@
2.33 s.scan(new TreePath(treePath,initializer), null);
2.34 break;
2.35 }
2.36 - safe = true;
2.37 } catch (FoundInstanceReference e) {
2.38 safe = false;
2.39 }
3.1 --- a/javahints/test/unit/src/org/netbeans/modules/javahints/MakeStaticTest.java Tue Jan 25 09:50:02 2011 +0100
3.2 +++ b/javahints/test/unit/src/org/netbeans/modules/javahints/MakeStaticTest.java Mon Jan 31 15:42:25 2011 +0100
3.3 @@ -162,6 +162,36 @@
3.4 "}").replaceAll("[ \t\n]+", " "));
3.5 }
3.6
3.7 + public void testNoNPE194745a() throws Exception {
3.8 + performAnalysisTest("test/Test.java",
3.9 + "package test;" +
3.10 + "public class Test {" +
3.11 + " abstract void test();" +
3.12 + " private static void testStatic() {" +
3.13 + " te|st();" +
3.14 + " }" +
3.15 + "}");
3.16 + }
3.17 +
3.18 + public void testNoNPE194745b() throws Exception {
3.19 + performFixTest("test/Test.java",
3.20 + "package test;" +
3.21 + "public class Test {" +
3.22 + " void test();" +
3.23 + " private static void testStatic() {" +
3.24 + " te|st();" +
3.25 + " }" +
3.26 + "}",
3.27 + "FixImpl:test:true",
3.28 + ("package test;" +
3.29 + "public class Test {" +
3.30 + " static void test();" +
3.31 + " private static void testStatic() {" +
3.32 + " test();" +
3.33 + " }" +
3.34 + "}").replaceAll("[ \t\n]+", " "));
3.35 + }
3.36 +
3.37 @Override
3.38 protected List<Fix> computeFixes(CompilationInfo info, int pos, TreePath path) throws Exception {
3.39 return new MakeStatic().run(info, null, pos, path, null);