#193583: preventing NPE for method without body inside a NCT.
authorJan Lahoda <jlahoda@netbeans.org>
Thu, 23 Dec 2010 21:39:50 +0100
changeset 17266a812a86e0729
parent 17264 0a5ebec019f7
child 17267 f39b5a3d6c19
#193583: preventing NPE for method without body inside a NCT.
java.ext.editor/nbproject/project.properties
java.ext.editor/src/org/netbeans/modules/java/editor/ext/fold/ShorteningFold.java
java.ext.editor/test/unit/src/org/netbeans/modules/java/editor/ext/fold/ShorteningFoldTest.java
     1.1 --- a/java.ext.editor/nbproject/project.properties	Wed Dec 08 19:07:41 2010 -0500
     1.2 +++ b/java.ext.editor/nbproject/project.properties	Thu Dec 23 21:39:50 2010 +0100
     1.3 @@ -2,3 +2,4 @@
     1.4  javac.compilerargs=-Xlint -Xlint:-serial
     1.5  nbm.module.author=jlahoda@netbeans.org
     1.6  spec.version.base=1.26.0
     1.7 +requires.nb.javac=true
     2.1 --- a/java.ext.editor/src/org/netbeans/modules/java/editor/ext/fold/ShorteningFold.java	Wed Dec 08 19:07:41 2010 -0500
     2.2 +++ b/java.ext.editor/src/org/netbeans/modules/java/editor/ext/fold/ShorteningFold.java	Thu Dec 23 21:39:50 2010 +0100
     2.3 @@ -288,6 +288,10 @@
     2.4                  return false;
     2.5              }
     2.6  
     2.7 +            if (decl.getBody() == null) {
     2.8 +                return true; //something is broken inside the anonymous class - do not try to shorten the NCT's type params
     2.9 +            }
    2.10 +
    2.11              boolean collapsed = FoldTypes.CLOSURE.collapsed();
    2.12              SourcePositions sp = info.getTrees().getSourcePositions();
    2.13              int nctStart = (int) sp.getStartPosition(info.getCompilationUnit(), nct);
     3.1 --- a/java.ext.editor/test/unit/src/org/netbeans/modules/java/editor/ext/fold/ShorteningFoldTest.java	Wed Dec 08 19:07:41 2010 -0500
     3.2 +++ b/java.ext.editor/test/unit/src/org/netbeans/modules/java/editor/ext/fold/ShorteningFoldTest.java	Thu Dec 23 21:39:50 2010 +0100
     3.3 @@ -165,6 +165,52 @@
     3.4                      "}");
     3.5      }
     3.6  
     3.7 +    public void test193583a() throws Exception {
     3.8 +        performTest("package test;" +
     3.9 +                    "public class Test {" +
    3.10 +                    "    public static void main(Map<String, String> m) {" +
    3.11 +                    "        main(new Map<String, String>() {" +
    3.12 +                    "            public String map(String p)" +
    3.13 +                    "        });" +
    3.14 +                    "    }" +
    3.15 +                    "    public static interface Map<R, P> {" +
    3.16 +                    "        public R map(P p);" +
    3.17 +                    "    }" +
    3.18 +                    "}",
    3.19 +                    "package test;" +
    3.20 +                    "public class Test {" +
    3.21 +                    "    public static void main(Map<String, String> m) {" +
    3.22 +                    "        main(new Map<String, String>() {" +
    3.23 +                    "            public String map(String p)" +
    3.24 +                    "        });" +
    3.25 +                    "    }" +
    3.26 +                    "    public static interface Map<R, P> {" +
    3.27 +                    "        public R map(P p);" +
    3.28 +                    "    }" +
    3.29 +                    "}");
    3.30 +    }
    3.31 +
    3.32 +    public void test193583b() throws Exception {
    3.33 +        performTest("package test;" +
    3.34 +                    "public class Test {" +
    3.35 +                    "    public static void main(Map<String, String> m) {" +
    3.36 +                    "        main(new Map<String, String>());" +
    3.37 +                    "    }" +
    3.38 +                    "    public static interface Map<R, P> {" +
    3.39 +                    "        public R map(P p);" +
    3.40 +                    "    }" +
    3.41 +                    "}",
    3.42 +                    "package test;" +
    3.43 +                    "public class Test {" +
    3.44 +                    "    public static void main(Map<String, String> m) {" +
    3.45 +                    "        main(new Map<String, String>());" +
    3.46 +                    "    }" +
    3.47 +                    "    public static interface Map<R, P> {" +
    3.48 +                    "        public R map(P p);" +
    3.49 +                    "    }" +
    3.50 +                    "}");
    3.51 +    }
    3.52 +
    3.53      public void testDiamondNCT() throws Exception {
    3.54          performTest("package test;" +
    3.55                      "import java.util.LinkedList;" +