#166988: preventing NPE.
authorJan Lahoda <jlahoda@netbeans.org>
Sun, 06 Jan 2013 19:12:11 +0100
changeset 17904f7635c415afc
parent 17903 609aa2c6a4a0
child 17905 af4aac727a19
#166988: preventing NPE.
javahints/src/org/netbeans/modules/javahints/MakeStatic.java
javahints/test/unit/src/org/netbeans/modules/javahints/MakeStaticTest.java
     1.1 --- a/javahints/src/org/netbeans/modules/javahints/MakeStatic.java	Wed Dec 26 09:13:48 2012 +0100
     1.2 +++ b/javahints/src/org/netbeans/modules/javahints/MakeStatic.java	Sun Jan 06 19:12:11 2013 +0100
     1.3 @@ -80,6 +80,9 @@
     1.4  
     1.5      public List<Fix> run(final CompilationInfo info, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
     1.6          Element el = info.getTrees().getElement(treePath);
     1.7 +        
     1.8 +        if (el == null) return null;
     1.9 +        
    1.10          final TypeElement topLevel = info.getElementUtilities().outermostTypeElement(el);
    1.11  
    1.12          //XXX: necessary to verify that el is from the current comp. unit?
     2.1 --- a/javahints/test/unit/src/org/netbeans/modules/javahints/MakeStaticTest.java	Wed Dec 26 09:13:48 2012 +0100
     2.2 +++ b/javahints/test/unit/src/org/netbeans/modules/javahints/MakeStaticTest.java	Sun Jan 06 19:12:11 2013 +0100
     2.3 @@ -40,6 +40,7 @@
     2.4  package org.netbeans.modules.javahints;
     2.5  import com.sun.source.util.TreePath;
     2.6  import java.util.List;
     2.7 +import java.util.Set;
     2.8  import org.netbeans.api.java.source.CompilationInfo;
     2.9  import org.netbeans.modules.java.hints.infrastructure.ErrorHintsTestBase;
    2.10  import org.netbeans.modules.javahints.MakeStatic.FixImpl;
    2.11 @@ -192,6 +193,19 @@
    2.12                         "}").replaceAll("[ \t\n]+", " "));
    2.13      }
    2.14      
    2.15 +    public void test166988() throws Exception {
    2.16 +        performAnalysisTest("test/Test.java",
    2.17 +                            "public class Test {" +
    2.18 +                            "    String rootDir = \"\";\n" +
    2.19 +                            "    public static void main(String[] args) {\n" +
    2.20 +                            "        if (args.length)\n" +
    2.21 +                            "\n" +
    2.22 +                            "        String[] foo = new File(rootDir).list(DirectoryFileFilter.DIRECTORY);\n" +
    2.23 +                            "    }\n" +
    2.24 +                            "}",
    2.25 +                            -1);
    2.26 +    }
    2.27 +    
    2.28      @Override
    2.29      protected List<Fix> computeFixes(CompilationInfo info, int pos, TreePath path) throws Exception {
    2.30          return new MakeStatic().run(info, null, pos, path, null);
    2.31 @@ -204,4 +218,9 @@
    2.32          return "FixImpl:" + fi.getName() + ":" + fi.isSafe();
    2.33      }
    2.34  
    2.35 +    @Override
    2.36 +    protected Set<String> getSupportedErrorKeys() {
    2.37 +        return new MakeStatic().getCodes();
    2.38 +    }
    2.39 +
    2.40  }
    2.41 \ No newline at end of file