From 52bd186bf72d2f475f2fd626a8533d79e3a7652d Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Sun, 6 Jun 2021 09:33:13 -0500 Subject: [PATCH] Eclipse 4.20 (RC2) JDT Patch for Groovy-Eclipse: JDT commit 0fc92c0 #1233 #1234 --- groovy-eclipse.setup | 2 +- .../feature.xml | 2 +- .../regression/LambdaRegressionTest.java | 1060 +++++++++-------- .../regression/PatternMatching16Test.java | 86 +- .../internal/compiler/ast/IfStatement.java | 11 +- .../compiler/ast/InstanceOfExpression.java | 1 - .../jdt/internal/compiler/lookup/Scope.java | 2 +- .../e420/org.eclipse.jdt.core/readme.txt | 1 + pom.xml | 2 +- 9 files changed, 657 insertions(+), 510 deletions(-) diff --git a/groovy-eclipse.setup b/groovy-eclipse.setup index f91c101401..d4c758f4b2 100644 --- a/groovy-eclipse.setup +++ b/groovy-eclipse.setup @@ -291,7 +291,7 @@ + url="https://download.eclipse.org/eclipse/updates/4.20-I-builds/I20210603-0040"/> diff --git a/jdt-patch/e420/Feature-org.codehaus.groovy.jdt.patch/feature.xml b/jdt-patch/e420/Feature-org.codehaus.groovy.jdt.patch/feature.xml index 4c6b93afc8..dce623d085 100644 --- a/jdt-patch/e420/Feature-org.codehaus.groovy.jdt.patch/feature.xml +++ b/jdt-patch/e420/Feature-org.codehaus.groovy.jdt.patch/feature.xml @@ -18,7 +18,7 @@ - + System.out.println(text));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot refer to \'this\' nor \'super\' while explicitly invoking a constructor\n" + + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " super(s -> System.out.println(text));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot refer to \'this\' nor \'super\' while explicitly invoking a constructor\n" + "----------\n" ); } -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=446317, java.lang.VerifyError: Bad type on operand stack with Lambdas and/or inner classes +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=446317, java.lang.VerifyError: Bad type on operand stack with Lambdas and/or inner classes public void test003() { this.runNegativeTest( new String[] { @@ -141,25 +141,25 @@ public void test004() { false, JavacHasABug.JavacThrowsAnException, new String[] { - "Y.java", - "import java.util.function.Supplier;\n" + - "class E {\n" + - " E(Supplier factory) { }\n" + - "}\n" + - "public class Y extends E {\n" + - " Y() {\n" + - " super( () -> {\n" + - " class Z extends E {\n" + - " Z() {\n" + - " super(() -> new Object());\n" + - " }\n" + - " }\n" + - " return null;\n" + - " });\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " new Y();\n" + - " }\n" + + "Y.java", + "import java.util.function.Supplier;\n" + + "class E {\n" + + " E(Supplier factory) { }\n" + + "}\n" + + "public class Y extends E {\n" + + " Y() {\n" + + " super( () -> {\n" + + " class Z extends E {\n" + + " Z() {\n" + + " super(() -> new Object());\n" + + " }\n" + + " }\n" + + " return null;\n" + + " });\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Y();\n" + + " }\n" + "}" }, null); @@ -168,7 +168,7 @@ public void test004() { public void test448724() { this.runConformTest( new String[] { - "X.java", + "X.java", "import java.util.concurrent.Callable;\n" + "public class X {\n" + " public void mismatchRunnableCallable() throws Exception {\n" + @@ -201,16 +201,16 @@ public void test448724() { " }\n" + "}\n" }, - "case1: Runnable\n" + - "case1: Runnable\n" + - "case2: Runnable\n" + + "case1: Runnable\n" + + "case1: Runnable\n" + + "case2: Runnable\n" + "case2: Runnable"); } -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference public void test447767() { this.runConformTest( new String[] { - "X.java", + "X.java", "interface I {\n" + " T goo(U u, V v);\n" + "}\n" + @@ -233,11 +233,11 @@ public void test447767() { }, "Right!"); } -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference public void test447767a() { this.runNegativeTest( new String[] { - "X.java", + "X.java", "interface I {\n" + " T goo(U u, V v);\n" + "}\n" + @@ -253,18 +253,18 @@ public void test447767a() { " }\n" + "}\n" }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " String s = goo(foo(\"String\", \"String\", (u, v) -> v));\n" + - " ^\n" + - "Type mismatch: cannot convert from Object to String\n" + + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " String s = goo(foo(\"String\", \"String\", (u, v) -> v));\n" + + " ^\n" + + "Type mismatch: cannot convert from Object to String\n" + "----------\n"); } -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference public void test447767b() { this.runConformTest( new String[] { - "X.java", + "X.java", "interface I {\n" + " T goo(U u, V v);\n" + "}\n" + @@ -286,11 +286,11 @@ public void test447767b() { }, "Right!"); } -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference public void test447767c() { this.runConformTest( new String[] { - "X.java", + "X.java", "interface I {\n" + " T goo(U u, V v);\n" + "}\n" + @@ -316,11 +316,11 @@ public void test447767c() { }, "Right!"); } -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference public void test447767d() { this.runConformTest( new String[] { - "X.java", + "X.java", "interface I {\n" + " T goo(U u, V v);\n" + "}\n" + @@ -346,11 +346,11 @@ public void test447767d() { }, "Right!"); } -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449410, [1.8][compiler] Eclipse java compiler does not detect a bad return type in lambda expression +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449410, [1.8][compiler] Eclipse java compiler does not detect a bad return type in lambda expression public void test449410() { this.runNegativeTest( new String[] { - "X.java", + "X.java", "import java.util.Collections;\n" + "public class X {\n" + " public static void main(String[] args) {\n" + @@ -367,24 +367,24 @@ public void test449410() { " }\n" + "}\n" }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " .forEach(entry -> test() ? bad() : returnType());\n" + - " ^^^^^^^\n" + - "The method forEach(Consumer>) in the type Iterable> is not applicable for the arguments (( entry) -> {})\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " .forEach(entry -> test() ? bad() : returnType());\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " .forEach(entry -> test() ? bad() : returnType());\n" + + " ^^^^^^^\n" + + "The method forEach(Consumer>) in the type Iterable> is not applicable for the arguments (( entry) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " .forEach(entry -> test() ? bad() : returnType());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Invalid expression as statement\n" + "----------\n"); } -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449824, [1.8] Difference in behaviour with method references and lambdas +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449824, [1.8] Difference in behaviour with method references and lambdas // Captures present behavior - may not be correct. public void test449824() { this.runNegativeTest( new String[] { - "X.java", + "X.java", "public class X {\n" + " public static void main(String[] args) {\n" + " Concrete fl = new Concrete();\n" + @@ -416,23 +416,23 @@ public void test449824() { " }\n" + "}\n" }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " fl.call(each -> each.doSomething()); // fails\n" + - " ^^^^\n" + - "The method call(X.RightHand) is ambiguous for the type X.Concrete\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " fl.call(Target::doSomething); // succeeds in Eclipse 4.5M3 and 4.4.1\n" + - " ^^^^\n" + - "The method call(X.RightHand) is ambiguous for the type X.Concrete\n" + + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " fl.call(each -> each.doSomething()); // fails\n" + + " ^^^^\n" + + "The method call(X.RightHand) is ambiguous for the type X.Concrete\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " fl.call(Target::doSomething); // succeeds in Eclipse 4.5M3 and 4.4.1\n" + + " ^^^^\n" + + "The method call(X.RightHand) is ambiguous for the type X.Concrete\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=448954, [1.8][compiler] Suspect error: "The method foo(String, String, X::goo) is undefined for the type X" public void test448954() { this.runConformTest( new String[] { - "X.java", + "X.java", "interface I {\n" + " T goo(U u, V v);\n" + "}\n" + @@ -465,7 +465,7 @@ public void test448954() { public void test450380() { this.runNegativeTest( new String[] { - "X.java", + "X.java", "import java.util.ArrayList;\n" + "import java.util.function.IntFunction;\n" + "public class X {\n" + @@ -474,18 +474,18 @@ public void test450380() { " }\n" + "}\n" }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " return System::new;\n" + - " ^^^^^^^^^^^\n" + - "The type System does not define System(int) that is applicable here\n" + + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return System::new;\n" + + " ^^^^^^^^^^^\n" + + "The type System does not define System(int) that is applicable here\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=450604, [1.8] CCE at InferenceContext18.getParameter line 1377 public void test450604() { this.runNegativeTest( new String[] { - "X.java", + "X.java", "import java.io.IOException;\n" + "import java.util.List;\n" + "import java.util.function.Function;\n" + @@ -503,7 +503,7 @@ public void test450604() { public void test450604a() { this.runConformTest( new String[] { - "X.java", + "X.java", "import java.util.List;\n" + "public class X {\n" + " public static List of() { return null; }\n" + @@ -514,11 +514,11 @@ public void test450604a() { "}\n" }); } -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=451677, [1.8][compiler] missing type inference +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=451677, [1.8][compiler] missing type inference public void _test451677() { this.runConformTest( new String[] { - "X.java", + "X.java", "import java.util.ArrayList;\n" + "import java.util.function.Function;\n" + "public class X {\n" + @@ -539,20 +539,20 @@ public void _test451677() { public void testBug451840() { runNegativeTest(new String [] { "X.java", - "public class X {\n" + - " public static void main(String[] args) {\n" + - " X test = new X();\n" + - " MySupplier s = test::new; // incorrect\n" + - " }\n" + - " public interface MySupplier {\n" + - " T create();\n" + - " }\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X test = new X();\n" + + " MySupplier s = test::new; // incorrect\n" + + " }\n" + + " public interface MySupplier {\n" + + " T create();\n" + + " }\n" + "}"}, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " MySupplier s = test::new; // incorrect\n" + - " ^^^^\n" + - "test cannot be resolved to a type\n" + + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " MySupplier s = test::new; // incorrect\n" + + " ^^^^\n" + + "test cannot be resolved to a type\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=448556 @@ -560,19 +560,19 @@ public void testBug451840() { public void testBug4448556() { this.runConformTest(new String [] { "X.java", - "import java.io.Serializable;\n" + - "import java.util.Arrays;\n" + - "import java.util.List;\n" + - "public class X {\n" + - " private static final List INTEGERS = Arrays.asList(1, 2, 3, 4);\n" + - " public static void main(String[] args) {\n" + - " for (int i = 0; i < INTEGERS.size(); i++) {\n" + - " MyPredicate predicate = INTEGERS.get(i)::equals;\n" + - " }\n" + - " } \n" + - " public interface MyPredicate extends Serializable {\n" + - " boolean accept(T each);\n" + - " }\n" + + "import java.io.Serializable;\n" + + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " private static final List INTEGERS = Arrays.asList(1, 2, 3, 4);\n" + + " public static void main(String[] args) {\n" + + " for (int i = 0; i < INTEGERS.size(); i++) {\n" + + " MyPredicate predicate = INTEGERS.get(i)::equals;\n" + + " }\n" + + " } \n" + + " public interface MyPredicate extends Serializable {\n" + + " boolean accept(T each);\n" + + " }\n" + "}" }, ""); @@ -582,23 +582,23 @@ public void testBug4448556() { public void testBug4448556a() { this.runConformTest(new String [] { "X.java", - "import java.io.Serializable;\n" + - "import java.util.Arrays;\n" + - "import java.util.List;\n" + - "public class X {\n" + - " int value = 0; \n" + - " private static final List INTEGERS = Arrays.asList(1, 2, 3, 4);\n" + - " public Integer next() {\n" + - " return new Integer(++value);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " X t = new X();\n" + - " MyPredicate predicate = t.next()::equals;\n" + - " System.out.println(\"Value \" + t.value + \" accept \" + predicate.accept(t.value));\n" + - " }\n" + - " public interface MyPredicate extends Serializable {\n" + - " boolean accept(T each);\n" + - " }\n" + + "import java.io.Serializable;\n" + + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " int value = 0; \n" + + " private static final List INTEGERS = Arrays.asList(1, 2, 3, 4);\n" + + " public Integer next() {\n" + + " return new Integer(++value);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X t = new X();\n" + + " MyPredicate predicate = t.next()::equals;\n" + + " System.out.println(\"Value \" + t.value + \" accept \" + predicate.accept(t.value));\n" + + " }\n" + + " public interface MyPredicate extends Serializable {\n" + + " boolean accept(T each);\n" + + " }\n" + "}" }, "Value 1 accept true"); @@ -608,18 +608,18 @@ public void testBug4448556a() { public void testBug453687() { this.runConformTest(new String [] { "X.java", - "import static java.util.stream.Collectors.groupingBy;\n" + - "import static java.util.stream.Collectors.mapping;\n" + - "import static java.util.stream.Collectors.toSet;\n" + - "import java.util.Locale;\n" + - "import java.util.Map;\n" + - "import java.util.Set;\n" + - "import java.util.stream.Stream;\n" + - "public class X {\n" + - " public static void main(String[] args) {\n" + - " Map> countryLanguagesMap = Stream.of(Locale.getAvailableLocales()).collect(\n" + - " groupingBy(Locale::getDisplayCountry, mapping(Locale::getDisplayLanguage, toSet())));\n" + - " }\n" + + "import static java.util.stream.Collectors.groupingBy;\n" + + "import static java.util.stream.Collectors.mapping;\n" + + "import static java.util.stream.Collectors.toSet;\n" + + "import java.util.Locale;\n" + + "import java.util.Map;\n" + + "import java.util.Set;\n" + + "import java.util.stream.Stream;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Map> countryLanguagesMap = Stream.of(Locale.getAvailableLocales()).collect(\n" + + " groupingBy(Locale::getDisplayCountry, mapping(Locale::getDisplayLanguage, toSet())));\n" + + " }\n" + "} " }, ""); @@ -629,60 +629,60 @@ public void testBug453687() { public void testBug456481() { this.runConformTest(new String [] { "Test.java", - "public class Test {\n" + - " interface Constructor {\n" + - " MyTest execute();\n" + - " }\n" + - " interface ArrayConstructor {\n" + - " MyTest[] execute(int no);\n" + - " }\n" + - " interface ParameterizedConstructor {\n" + - " MyParameterizedTest execute();\n" + - " }\n" + - " class MyTest {\n" + - " MyTest() { System.out.println(\"Constructor executed\"); }\n" + - " }\n" + - " class MyParameterizedTest {\n" + - " MyParameterizedTest() {\n" + - " System.out.println(\"Parameterized Constructor executed\");\n" + - " }\n" + - " }\n" + - " public Constructor getConstructor() {\n" + - " return getConstructor(() -> { return MyTest::new; });\n" + - " }\n" + - " public MyTest[] getArray(int no) {\n" + - " return new MyTest[no];\n" + - " }\n" + - " ArrayConstructor getArrayConstructor() {\n" + - " return getArrayConstructor(() -> {return MyTest[]::new;});\n" + - " }\n" + - " ParameterizedConstructor getParameterizedConstructor() {\n" + - " return getParameterizedConstructor(() -> {return MyParameterizedTest::new;});\n" + - " }\n" + - " ArrayConstructor getArrayConstructor(ArrayWrapper w) {\n" + - " return w.unwrap();\n" + - " }\n" + - " public static void main(String argv[]) {\n" + - " Test t = new Test();\n" + - " MyTest mytest = t.getConstructor().execute();\n" + + "public class Test {\n" + + " interface Constructor {\n" + + " MyTest execute();\n" + + " }\n" + + " interface ArrayConstructor {\n" + + " MyTest[] execute(int no);\n" + + " }\n" + + " interface ParameterizedConstructor {\n" + + " MyParameterizedTest execute();\n" + + " }\n" + + " class MyTest {\n" + + " MyTest() { System.out.println(\"Constructor executed\"); }\n" + + " }\n" + + " class MyParameterizedTest {\n" + + " MyParameterizedTest() {\n" + + " System.out.println(\"Parameterized Constructor executed\");\n" + + " }\n" + + " }\n" + + " public Constructor getConstructor() {\n" + + " return getConstructor(() -> { return MyTest::new; });\n" + + " }\n" + + " public MyTest[] getArray(int no) {\n" + + " return new MyTest[no];\n" + + " }\n" + + " ArrayConstructor getArrayConstructor() {\n" + + " return getArrayConstructor(() -> {return MyTest[]::new;});\n" + + " }\n" + + " ParameterizedConstructor getParameterizedConstructor() {\n" + + " return getParameterizedConstructor(() -> {return MyParameterizedTest::new;});\n" + + " }\n" + + " ArrayConstructor getArrayConstructor(ArrayWrapper w) {\n" + + " return w.unwrap();\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " Test t = new Test();\n" + + " MyTest mytest = t.getConstructor().execute();\n" + " MyTest[] array = t.getArrayConstructor().execute(2);\n" + " MyParameterizedTest pt = t.getParameterizedConstructor().execute();\n" + - " }\n" + - " ParameterizedConstructor getParameterizedConstructor(PTWrapper ptw) {\n" + - " return ptw.unwrap();\n" + - " }\n" + - " Constructor getConstructor(Wrapper arg) {\n" + - " return arg.unwrap();\n" + - " }\n" + - " interface PTWrapper {\n" + - " ParameterizedConstructor unwrap();\n" + - " }\n" + - " interface ArrayWrapper {\n" + - " ArrayConstructor unwrap();\n" + - " }\n" + - " interface Wrapper {\n" + - " Constructor unwrap();\n" + - " }\n" + + " }\n" + + " ParameterizedConstructor getParameterizedConstructor(PTWrapper ptw) {\n" + + " return ptw.unwrap();\n" + + " }\n" + + " Constructor getConstructor(Wrapper arg) {\n" + + " return arg.unwrap();\n" + + " }\n" + + " interface PTWrapper {\n" + + " ParameterizedConstructor unwrap();\n" + + " }\n" + + " interface ArrayWrapper {\n" + + " ArrayConstructor unwrap();\n" + + " }\n" + + " interface Wrapper {\n" + + " Constructor unwrap();\n" + + " }\n" + "}" }, "Constructor executed\n" + @@ -708,192 +708,192 @@ public void testBug457007() { public void testBug446691_comment5() { runConformTest(new String [] { "Test.java", - "import java.util.*;\n" + - "\n" + - "public class Test {\n" + - " protected final Integer myInt;\n" + - "\n" + - " public Test() {\n" + - " myInt = Integer.valueOf(0);\n" + - " try {\n" + - " Optional.empty().orElseThrow(() -> new IllegalArgumentException(myInt.toString()));\n" + - " } catch (IllegalArgumentException e) {\n" + - " throw new RuntimeException();\n" + - " }\n" + - " return;\n" + - " }\n" + + "import java.util.*;\n" + + "\n" + + "public class Test {\n" + + " protected final Integer myInt;\n" + + "\n" + + " public Test() {\n" + + " myInt = Integer.valueOf(0);\n" + + " try {\n" + + " Optional.empty().orElseThrow(() -> new IllegalArgumentException(myInt.toString()));\n" + + " } catch (IllegalArgumentException e) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " return;\n" + + " }\n" + "}\n" }); } public void testBug446691_comment8() { runConformTest(new String [] { "Boom.java", - "public class Boom {\n" + - " private final String field;\n" + - " public Boom(String arg) {\n" + - " this.field = arg;\n" + - " try {\n" + - " java.util.function.Supplier supplier = () -> field;\n" + - " } catch (Exception e) {\n" + - " \n" + - " }\n" + - " }\n" + + "public class Boom {\n" + + " private final String field;\n" + + " public Boom(String arg) {\n" + + " this.field = arg;\n" + + " try {\n" + + " java.util.function.Supplier supplier = () -> field;\n" + + " } catch (Exception e) {\n" + + " \n" + + " }\n" + + " }\n" + "}\n" }); } public void testBug446691_comment14() { runNegativeTest(new String [] { "test/Main.java", - "package test;\n" + - "\n" + - "import java.util.logging.Logger;\n" + - "\n" + - "public class Main {\n" + - "\n" + - " private static final Logger LOG = Logger.getLogger(\"test\");\n" + - " private final static String value;\n" + - "\n" + - " static {\n" + - " try {\n" + - " LOG.info(() -> String.format(\"Value is: %s\", value));\n" + - " } catch (final Exception ex) {\n" + - " throw new ExceptionInInitializerError(ex);\n" + - " }\n" + - " }\n" + + "package test;\n" + + "\n" + + "import java.util.logging.Logger;\n" + + "\n" + + "public class Main {\n" + + "\n" + + " private static final Logger LOG = Logger.getLogger(\"test\");\n" + + " private final static String value;\n" + + "\n" + + " static {\n" + + " try {\n" + + " LOG.info(() -> String.format(\"Value is: %s\", value));\n" + + " } catch (final Exception ex) {\n" + + " throw new ExceptionInInitializerError(ex);\n" + + " }\n" + + " }\n" + "}" }, - "----------\n" + - "1. ERROR in test\\Main.java (at line 8)\n" + - " private final static String value;\n" + - " ^^^^^\n" + - "The blank final field value may not have been initialized\n" + - "----------\n" + - "2. ERROR in test\\Main.java (at line 12)\n" + - " LOG.info(() -> String.format(\"Value is: %s\", value));\n" + - " ^^^^^\n" + - "The blank final field value may not have been initialized\n" + + "----------\n" + + "1. ERROR in test\\Main.java (at line 8)\n" + + " private final static String value;\n" + + " ^^^^^\n" + + "The blank final field value may not have been initialized\n" + + "----------\n" + + "2. ERROR in test\\Main.java (at line 12)\n" + + " LOG.info(() -> String.format(\"Value is: %s\", value));\n" + + " ^^^^^\n" + + "The blank final field value may not have been initialized\n" + "----------\n"); } // error in lambda even if field is assigned later public void testBug446691_comment14b() { runNegativeTest(new String [] { "test/Main.java", - "package test;\n" + - "\n" + - "import java.util.logging.Logger;\n" + - "\n" + - "public class Main {\n" + - "\n" + - " private static final Logger LOG = Logger.getLogger(\"test\");\n" + - " private final static String value;\n" + - "\n" + - " static {\n" + - " try {\n" + - " LOG.info(() -> String.format(\"Value is: %s\", value));\n" + - " } catch (final Exception ex) {\n" + - " throw new ExceptionInInitializerError(ex);\n" + + "package test;\n" + + "\n" + + "import java.util.logging.Logger;\n" + + "\n" + + "public class Main {\n" + + "\n" + + " private static final Logger LOG = Logger.getLogger(\"test\");\n" + + " private final static String value;\n" + + "\n" + + " static {\n" + + " try {\n" + + " LOG.info(() -> String.format(\"Value is: %s\", value));\n" + + " } catch (final Exception ex) {\n" + + " throw new ExceptionInInitializerError(ex);\n" + " }\n" + - " value = \"\";" + - " }\n" + + " value = \"\";" + + " }\n" + "}" }, - "----------\n" + - "1. ERROR in test\\Main.java (at line 12)\n" + - " LOG.info(() -> String.format(\"Value is: %s\", value));\n" + - " ^^^^^\n" + - "The blank final field value may not have been initialized\n" + + "----------\n" + + "1. ERROR in test\\Main.java (at line 12)\n" + + " LOG.info(() -> String.format(\"Value is: %s\", value));\n" + + " ^^^^^\n" + + "The blank final field value may not have been initialized\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=463526 -// Parenthesis are incorrectly allowed in lambda when LambdaBody is an expression statement +// Parenthesis are incorrectly allowed in lambda when LambdaBody is an expression statement public void testBug463526() { runNegativeTest(new String [] { "Test.java", - "public class Test {\n" + - " public static void main(String[] args) {\n" + - " Receiver r = new Receiver();\n" + - " r.accept((l) -> (doItOnTheClass(new Object())));\n" + - " }\n" + - " public static void doItOnTheClass(Object o) {\n" + - " System.out.println(\"done it\");\n" + - " }\n" + - " public static class Receiver {\n" + - " public void accept(Listener l) {\n" + - " l.doIt(new Object());\n" + - " }\n" + - " }\n" + - " public static interface Listener {\n" + - " public void doIt(Object o);\n" + - " }\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " Receiver r = new Receiver();\n" + + " r.accept((l) -> (doItOnTheClass(new Object())));\n" + + " }\n" + + " public static void doItOnTheClass(Object o) {\n" + + " System.out.println(\"done it\");\n" + + " }\n" + + " public static class Receiver {\n" + + " public void accept(Listener l) {\n" + + " l.doIt(new Object());\n" + + " }\n" + + " }\n" + + " public static interface Listener {\n" + + " public void doIt(Object o);\n" + + " }\n" + "}" }, - "----------\n" + - "1. ERROR in Test.java (at line 4)\n" + - " r.accept((l) -> (doItOnTheClass(new Object())));\n" + - " ^^^^^^\n" + + "----------\n" + + "1. ERROR in Test.java (at line 4)\n" + + " r.accept((l) -> (doItOnTheClass(new Object())));\n" + + " ^^^^^^\n" + "The method accept(Test.Listener) in the type Test.Receiver is not applicable for the arguments (( l) -> {})\n" + - "----------\n" + - "2. ERROR in Test.java (at line 4)\n" + - " r.accept((l) -> (doItOnTheClass(new Object())));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "----------\n" + + "2. ERROR in Test.java (at line 4)\n" + + " r.accept((l) -> (doItOnTheClass(new Object())));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Invalid expression as statement\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=463526 -// Parenthesis are incorrectly allowed in lambda when LambdaBody is an expression statement +// Parenthesis are incorrectly allowed in lambda when LambdaBody is an expression statement public void testBug463526b() { runNegativeTest(new String [] { "Test.java", - "import java.util.function.Consumer;\n" + - "public class Test {\n" + - " public static void main(String[] args) {\n" + - " Receiver r = new Receiver();\n" + - " r.process((o) -> (new Object()));\n" + - " }\n" + - " public static class Receiver {\n" + - " public void process(Consumer p) {\n" + - " }\n" + - " }\n" + + "import java.util.function.Consumer;\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " Receiver r = new Receiver();\n" + + " r.process((o) -> (new Object()));\n" + + " }\n" + + " public static class Receiver {\n" + + " public void process(Consumer p) {\n" + + " }\n" + + " }\n" + "}" }, - "----------\n" + - "1. ERROR in Test.java (at line 5)\n" + - " r.process((o) -> (new Object()));\n" + - " ^^^^^^^\n" + + "----------\n" + + "1. ERROR in Test.java (at line 5)\n" + + " r.process((o) -> (new Object()));\n" + + " ^^^^^^^\n" + "The method process(Consumer) in the type Test.Receiver is not applicable for the arguments (( o) -> {})\n" + - "----------\n" + - "2. ERROR in Test.java (at line 5)\n" + - " r.process((o) -> (new Object()));\n" + - " ^^^^^^^^^^^^^^\n" + + "----------\n" + + "2. ERROR in Test.java (at line 5)\n" + + " r.process((o) -> (new Object()));\n" + + " ^^^^^^^^^^^^^^\n" + "Void methods cannot return a value\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=463526 -// Parenthesis are incorrectly allowed in lambda when LambdaBody is an expression statement +// Parenthesis are incorrectly allowed in lambda when LambdaBody is an expression statement public void testBug463526c() { runNegativeTest(new String [] { "Test.java", - "import java.util.function.Consumer;\n" + - "public class Test {\n" + - " public static void main(String[] args) {\n" + - " Receiver r = new Receiver();\n" + - " r.assign((o) -> (o = new Object()));\n" + - " }\n" + - " public static class Receiver {\n" + - " public void assign(Consumer a) {\n" + - " }\n" + - " }\n" + + "import java.util.function.Consumer;\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " Receiver r = new Receiver();\n" + + " r.assign((o) -> (o = new Object()));\n" + + " }\n" + + " public static class Receiver {\n" + + " public void assign(Consumer a) {\n" + + " }\n" + + " }\n" + "}" }, - "----------\n" + - "1. ERROR in Test.java (at line 5)\n" + - " r.assign((o) -> (o = new Object()));\n" + - " ^^^^^^\n" + - "The method assign(Consumer) in the type Test.Receiver is not applicable for the arguments (( o) -> {})\n" + - "----------\n" + - "2. ERROR in Test.java (at line 5)\n" + - " r.assign((o) -> (o = new Object()));\n" + - " ^^^^^^^^^^^^^^^^^^\n" + + "----------\n" + + "1. ERROR in Test.java (at line 5)\n" + + " r.assign((o) -> (o = new Object()));\n" + + " ^^^^^^\n" + + "The method assign(Consumer) in the type Test.Receiver is not applicable for the arguments (( o) -> {})\n" + + "----------\n" + + "2. ERROR in Test.java (at line 5)\n" + + " r.assign((o) -> (o = new Object()));\n" + + " ^^^^^^^^^^^^^^^^^^\n" + "Void methods cannot return a value\n" + "----------\n"); } @@ -909,11 +909,11 @@ public void testBug464408() { " list.stream().toArray(List[]::new);\n" + " }" + "}" - }, "----------\n" + - "1. ERROR in test\\X.java (at line 6)\n" + - " list.stream().toArray(List[]::new);\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Cannot create a generic array of List\n" + + }, "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " list.stream().toArray(List[]::new);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of List\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=465900 @@ -921,20 +921,20 @@ public void testBug464408() { public void testBug465900() { this.runConformTest(new String [] { "X.java", - "import java.io.Serializable;\n" + - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "import java.util.function.Supplier;\n" + - "public class X {\n" + - " private static final long serialVersionUID = 1L;\n" + - " protected void x() {\n" + - " String str = \"groep.koppeling.\" + (\"\".isEmpty() ? \"toevoegen\" : \"bewerken\");\n" + - " List bean = new ArrayList<>();\n" + - " test(bean.get(0)::isEmpty);\n" + - " }\n" + - " private void test(SerializableSupplier test) {}\n" + - "}\n" + - "@FunctionalInterface\n" + + "import java.io.Serializable;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.function.Supplier;\n" + + "public class X {\n" + + " private static final long serialVersionUID = 1L;\n" + + " protected void x() {\n" + + " String str = \"groep.koppeling.\" + (\"\".isEmpty() ? \"toevoegen\" : \"bewerken\");\n" + + " List bean = new ArrayList<>();\n" + + " test(bean.get(0)::isEmpty);\n" + + " }\n" + + " private void test(SerializableSupplier test) {}\n" + + "}\n" + + "@FunctionalInterface\n" + "interface SerializableSupplier extends Supplier, Serializable {}\n" }, ""); @@ -944,29 +944,29 @@ public void testBug465900() { public void testBug477888() { runNegativeTest(new String [] { "Test.java", - "import java.io.IOException;\n" + - "import java.nio.file.Files;\n" + - "import java.nio.file.Paths;\n" + - "import java.util.function.Consumer;\n" + - "public class Test {\n" + - " public static void main(String[] args) throws IOException {\n" + - " Files.lines(Paths.get(args[0])).filter(x -> {return !x.startsWith(\".\");}).forEach(printMe());\n" + - " }\n" + - " private static Consumer printMe() {\n" + - " return x -> x.isEmpty() ? System.out.println() : System.out.println(getIndex() + \" \" + x); // error must be reported here!\n" + - " }\n" + - " static int idx;\n" + - "\n" + - " private static int getIndex() {\n" + - " return ++idx;\n" + - " }\n" + + "import java.io.IOException;\n" + + "import java.nio.file.Files;\n" + + "import java.nio.file.Paths;\n" + + "import java.util.function.Consumer;\n" + + "public class Test {\n" + + " public static void main(String[] args) throws IOException {\n" + + " Files.lines(Paths.get(args[0])).filter(x -> {return !x.startsWith(\".\");}).forEach(printMe());\n" + + " }\n" + + " private static Consumer printMe() {\n" + + " return x -> x.isEmpty() ? System.out.println() : System.out.println(getIndex() + \" \" + x); // error must be reported here!\n" + + " }\n" + + " static int idx;\n" + + "\n" + + " private static int getIndex() {\n" + + " return ++idx;\n" + + " }\n" + "}\n" }, - "----------\n" + - "1. ERROR in Test.java (at line 10)\n" + - " return x -> x.isEmpty() ? System.out.println() : System.out.println(getIndex() + \" \" + x); // error must be reported here!\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Invalid expression as statement\n" + + "----------\n" + + "1. ERROR in Test.java (at line 10)\n" + + " return x -> x.isEmpty() ? System.out.println() : System.out.println(getIndex() + \" \" + x); // error must be reported here!\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Invalid expression as statement\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=472648 @@ -977,48 +977,48 @@ public void testBug472648() { JavacHasABug.JavacBugFixed_901, new String [] { "Test.java", - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "import java.util.function.Consumer;\n" + - "public class Test {\n" + - " public static void main(String argv[]) {\n" + - " new Test();\n" + - " }\n" + - " public Test() {\n" + - " List numList = new ArrayList<>();\n" + - " numList.add(1);\n" + - " numList.add(1.5);\n" + - " numList.add(2);\n" + - " numList.add(2.5);\n" + - " forEachValueOfType(numList, Integer.class, (Integer i) -> (System.out.println(Integer.toString(i))));\n" + - " }\n" + - " private void forEachValueOfType(List list, Class type, Consumer action) {\n" + - " \n" + - " for (Object o : list) {\n" + - " if (type.isAssignableFrom(o.getClass())) {\n" + - " @SuppressWarnings(\"unchecked\")\n" + - " T convertedObject = (T) o;\n" + - " action.accept(convertedObject);\n" + - " }\n" + - " }\n" + - " }\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.function.Consumer;\n" + + "public class Test {\n" + + " public static void main(String argv[]) {\n" + + " new Test();\n" + + " }\n" + + " public Test() {\n" + + " List numList = new ArrayList<>();\n" + + " numList.add(1);\n" + + " numList.add(1.5);\n" + + " numList.add(2);\n" + + " numList.add(2.5);\n" + + " forEachValueOfType(numList, Integer.class, (Integer i) -> (System.out.println(Integer.toString(i))));\n" + + " }\n" + + " private void forEachValueOfType(List list, Class type, Consumer action) {\n" + + " \n" + + " for (Object o : list) {\n" + + " if (type.isAssignableFrom(o.getClass())) {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " T convertedObject = (T) o;\n" + + " action.accept(convertedObject);\n" + + " }\n" + + " }\n" + + " }\n" + "}" }, - "----------\n" + - "1. ERROR in Test.java (at line 14)\n" + - " forEachValueOfType(numList, Integer.class, (Integer i) -> (System.out.println(Integer.toString(i))));\n" + - " ^^^^^^^^^^^^^^^^^^\n" + + "----------\n" + + "1. ERROR in Test.java (at line 14)\n" + + " forEachValueOfType(numList, Integer.class, (Integer i) -> (System.out.println(Integer.toString(i))));\n" + + " ^^^^^^^^^^^^^^^^^^\n" + "The method forEachValueOfType(List, Class, Consumer) in the type Test is not applicable for the arguments (List, Class, (Integer i) -> {})\n" + - "----------\n" + - "2. ERROR in Test.java (at line 14)\n" + - " forEachValueOfType(numList, Integer.class, (Integer i) -> (System.out.println(Integer.toString(i))));\n" + - " ^^^^^^^\n" + - "Incompatible type specified for lambda expression's parameter i\n" + - "----------\n" + - "3. ERROR in Test.java (at line 14)\n" + - " forEachValueOfType(numList, Integer.class, (Integer i) -> (System.out.println(Integer.toString(i))));\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Invalid expression as statement\n" + + "----------\n" + + "2. ERROR in Test.java (at line 14)\n" + + " forEachValueOfType(numList, Integer.class, (Integer i) -> (System.out.println(Integer.toString(i))));\n" + + " ^^^^^^^\n" + + "Incompatible type specified for lambda expression's parameter i\n" + + "----------\n" + + "3. ERROR in Test.java (at line 14)\n" + + " forEachValueOfType(numList, Integer.class, (Integer i) -> (System.out.println(Integer.toString(i))));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Invalid expression as statement\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=473432 @@ -1026,41 +1026,41 @@ public void testBug472648() { public void testBug473432() { this.runConformTest(new String [] { "Tester.java", - "import java.util.function.Function;\n" + - "public class Tester {\n" + - " private static class ValueWrapper {\n" + - " private O val_;\n" + - " public ValueWrapper(O val) {\n" + - " val_ = val;\n" + - " }\n" + - " public R mapOrElse(Function func, R defaultValue) {\n" + - " if(val_ != null) {\n" + - " return func.apply(val_);\n" + - " }\n" + - " return defaultValue;\n" + - " }\n" + - " }\n" + - " private static void handleObject(Object object) {\n" + - " System.out.println(\"Handled: \" + object);\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " ValueWrapper wrapper = new ValueWrapper<>(\"value\");\n" + - " boolean skipMethod = false;\n" + - " // works on both JDT 3.9.2 and 3.11.0\n" + - " Boolean result = skipMethod ? true : wrapper.mapOrElse(v -> false, null);\n" + - " System.out.println(result);\n" + - " wrapper = new ValueWrapper<>(null);\n" + - " // works on JDT 3.9.2\n" + - " handleObject(skipMethod ?\n" + - " true :\n" + - " wrapper.mapOrElse(v -> false, null));\n" + - " wrapper = new ValueWrapper<>(null);\n" + - " // works on neither version\n" + - " result = skipMethod ?\n" + - " true :\n" + - " wrapper.mapOrElse(v -> false, null);\n" + - " System.out.println(result);\n" + - " }\n" + + "import java.util.function.Function;\n" + + "public class Tester {\n" + + " private static class ValueWrapper {\n" + + " private O val_;\n" + + " public ValueWrapper(O val) {\n" + + " val_ = val;\n" + + " }\n" + + " public R mapOrElse(Function func, R defaultValue) {\n" + + " if(val_ != null) {\n" + + " return func.apply(val_);\n" + + " }\n" + + " return defaultValue;\n" + + " }\n" + + " }\n" + + " private static void handleObject(Object object) {\n" + + " System.out.println(\"Handled: \" + object);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " ValueWrapper wrapper = new ValueWrapper<>(\"value\");\n" + + " boolean skipMethod = false;\n" + + " // works on both JDT 3.9.2 and 3.11.0\n" + + " Boolean result = skipMethod ? true : wrapper.mapOrElse(v -> false, null);\n" + + " System.out.println(result);\n" + + " wrapper = new ValueWrapper<>(null);\n" + + " // works on JDT 3.9.2\n" + + " handleObject(skipMethod ?\n" + + " true :\n" + + " wrapper.mapOrElse(v -> false, null));\n" + + " wrapper = new ValueWrapper<>(null);\n" + + " // works on neither version\n" + + " result = skipMethod ?\n" + + " true :\n" + + " wrapper.mapOrElse(v -> false, null);\n" + + " System.out.println(result);\n" + + " }\n" + "}\n" }, "false\n" + @@ -1071,27 +1071,27 @@ public void testBug473432() { public void testBug511676() { this.runConformTest(new String [] { "A.java", - "import java.util.function.Function;\n" + - "public class A {\n" + - " interface C { }\n" + - " interface O {\n" + - " Object r(C s);\n" + - " }\n" + - " static O m(O source, Function> mapper) {\n" + - " return o -> {\n" + - " class D {\n" + - " class E {\n" + - " }\n" + - " E e = new E();\n" + - " }\n" + - " D d = new D();\n" + - " return d.e;\n" + - " };\n" + - " }\n" + - " public static void main(String[] args) {\n" + - " m(null, null);\n" + + "import java.util.function.Function;\n" + + "public class A {\n" + + " interface C { }\n" + + " interface O {\n" + + " Object r(C s);\n" + + " }\n" + + " static O m(O source, Function> mapper) {\n" + + " return o -> {\n" + + " class D {\n" + + " class E {\n" + + " }\n" + + " E e = new E();\n" + + " }\n" + + " D d = new D();\n" + + " return d.e;\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " m(null, null);\n" + " System.out.println(\" Done\");\n" + - " }\n" + + " }\n" + "}\n" }, "Done"); @@ -1100,24 +1100,24 @@ public void testBug511676() { public void testBug511676a() { this.runConformTest(new String [] { "A.java", - "public class A {\n" + - " interface C { }\n" + - " interface O {\n" + - " Object r(C s);\n" + - " }\n" + - " static O def = o -> {\n" + - " class D {\n" + - " class E {\n" + - " }\n" + - " E e = new E();\n" + - " }\n" + - " D d = new D();\n" + - " return d.e;\n" + - " };\n" + - " public static void main(String[] args) {\n" + + "public class A {\n" + + " interface C { }\n" + + " interface O {\n" + + " Object r(C s);\n" + + " }\n" + + " static O def = o -> {\n" + + " class D {\n" + + " class E {\n" + + " }\n" + + " E e = new E();\n" + + " }\n" + + " D d = new D();\n" + + " return d.e;\n" + + " };\n" + + " public static void main(String[] args) {\n" + " O o = A.def;\n" + " System.out.println(\" Done\");\n" + - " }\n" + + " }\n" + "}\n" }, "Done"); @@ -1127,42 +1127,96 @@ public void testBug543778() { runner.testFiles = new String[] { "Sandbox.java", - "import java.util.function.Supplier;\n" + - "\n" + - "public class Sandbox {\n" + - "\n" + - " R get(Supplier<@NonNull R> impl) {\n" + - " return null;\n" + - " }\n" + - "\n" + - " Object getter() {\n" + - " return get(() -> new Object() {\n" + - "\n" + - " @Override\n" + - " public String toString() {\n" + - " return super.toString();\n" + - " }\n" + - "\n" + - " });\n" + - " }\n" + - "\n" + + "import java.util.function.Supplier;\n" + + "\n" + + "public class Sandbox {\n" + + "\n" + + " R get(Supplier<@NonNull R> impl) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " Object getter() {\n" + + " return get(() -> new Object() {\n" + + "\n" + + " @Override\n" + + " public String toString() {\n" + + " return super.toString();\n" + + " }\n" + + "\n" + + " });\n" + + " }\n" + + "\n" + "}\n", "NonNull.java", - "import java.lang.annotation.ElementType;\n" + - "import java.lang.annotation.Retention;\n" + - "import java.lang.annotation.RetentionPolicy;\n" + - "import java.lang.annotation.Target;\n" + - "\n" + - "@Retention(RetentionPolicy.CLASS)\n" + - "@Target({ ElementType.TYPE_USE })\n" + - "public @interface NonNull {\n" + - " // marker annotation with no members\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ ElementType.TYPE_USE })\n" + + "public @interface NonNull {\n" + + " // marker annotation with no members\n" + "}\n", }; runner.customOptions = getCompilerOptions(); runner.customOptions.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); // bug happens due to type annotation handling runner.runConformTest(); } +public void test572873a() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + " static Iterable iterable() {\n" + + " return () -> new Iterator() {\n" + + " @Override\n" + + " public boolean hasNext() {\n" + + " return false;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public T next() {\n" + + " return null;\n" + + " }\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"test T\");\n" + + " }\n" + + "}", + }, + "test T" + ); +} +public void test572873b() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Consumer;\n" + + "\n" + + "public class X {\n" + + " public static void build(T element) {\n" + + " new Thread(() -> {\n" + + " new Consumer() {\n" + + "\n" + + " @Override\n" + + " public void accept(T t) {" + + "\n" + + " }\n" + + " };\n" + + " });\n" + + " }" + + " public static void main(String[] args) {\n" + + " System.out.println(\"test T\");\n" + + " }\n" + + "}", + }, + "test T" + ); +} public static Class testClass() { return LambdaRegressionTest.class; } diff --git a/jdt-patch/e420/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java b/jdt-patch/e420/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java index a933b29ce8..bcb28a1428 100644 --- a/jdt-patch/e420/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java +++ b/jdt-patch/e420/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java @@ -3707,7 +3707,7 @@ public void testBug572380_2() { "true", options); } - public void testBug572431() { + public void testBug572431_1() { Map options = getCompilerOptions(false); runConformTest( new String[] { @@ -3728,4 +3728,88 @@ public void testBug572431() { options); } + public void testBug572431_2() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static public void something () {\n" + + " boolean bool = true;\n" + + " Object object = null;\n" + + " if (object instanceof String string) {\n" + + " } else if (bool) {\n" + + " if (object instanceof Integer integer) {\n" + + " }\n" + + " }\n" + + " }\n" + + " static public void main (String[] args) throws Exception {\n" + + " }\n" + + "}", + }, + "", + options); + + } + public void testBug572431_3() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static public void something () {\n" + + " boolean bool = true;\n" + + " Object object = null;\n" + + " if (bool && object instanceof Integer i) {\n" + + " }\n" + + " }\n" + + " static public void main (String[] args) throws Exception {\n" + + " }\n" + + "}", + }, + "", + options); + + } + public void testBug572431_4() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static public void something () {\n" + + " boolean bool = true;\n" + + " Object object = null;\n" + + " if (!(object instanceof Integer i)) {\n" + + " }\n" + + " }\n" + + " static public void main (String[] args) throws Exception {\n" + + " }\n" + + "}", + }, + "", + options); + + } + public void testBug572431_5() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static public void something () {\n" + + " boolean bool = true;\n" + + " Object object = null;\n" + + " if (false) {\n" + + " } else if (!(object instanceof Integer i)) {\n" + + " }\n" + + " }\n" + + " static public void main (String[] args) throws Exception {\n" + + " }\n" + + "}", + }, + "", + options); + + } } diff --git a/jdt-patch/e420/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java b/jdt-patch/e420/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java index 05f5cb7949..d5af0e01b0 100644 --- a/jdt-patch/e420/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java +++ b/jdt-patch/e420/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java @@ -246,7 +246,16 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) { this.elseStatement.generateCode(currentScope, codeStream); } else { // generate condition side-effects - this.condition.generateCode(currentScope, codeStream, false); + if (this.condition.containsPatternVariable()) { + this.condition.generateOptimizedBoolean( + currentScope, + codeStream, + endifLabel, + null, + cst == Constant.NotAConstant); + } else { + this.condition.generateCode(currentScope, codeStream, false); + } codeStream.recordPositionsFrom(pc, this.sourceStart); } // May loose some local variable initializations : affecting the local variable attributes diff --git a/jdt-patch/e420/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java b/jdt-patch/e420/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java index 290cf55b0e..2a8745f271 100644 --- a/jdt-patch/e420/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java +++ b/jdt-patch/e420/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java @@ -160,7 +160,6 @@ public void generateOptimizedBoolean(BlockScope currentScope, CodeStream codeStr BranchLabel nextSibling = falseLabel != null ? falseLabel : new BranchLabel(codeStream); codeStream.instance_of(this.type, this.type.resolvedType); if (this.elementVariable != null) { - valueRequired = true; codeStream.ifeq(nextSibling); codeStream.load(this.secretInstanceOfPatternExpressionValue); codeStream.checkcast(this.type, this.type.resolvedType, codeStream.position); diff --git a/jdt-patch/e420/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java b/jdt-patch/e420/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java index dfd4493804..e623499b96 100644 --- a/jdt-patch/e420/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java +++ b/jdt-patch/e420/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java @@ -3397,7 +3397,7 @@ final Binding getTypeOrPackage(char[] name, int mask, boolean needResolve) { return typeVariable; } insideStaticContext |= sourceType.isStatic(); - insideClassContext = true; + insideClassContext = !sourceType.isAnonymousType(); insideTypeAnnotation = false; if (CharOperation.equals(sourceType.sourceName, name)) { if (foundType != null && TypeBinding.notEquals(foundType, sourceType) && foundType.problemId() != ProblemReasons.NotVisible) diff --git a/jdt-patch/e420/org.eclipse.jdt.core/readme.txt b/jdt-patch/e420/org.eclipse.jdt.core/readme.txt index 564b6b23d5..6d1728c857 100644 --- a/jdt-patch/e420/org.eclipse.jdt.core/readme.txt +++ b/jdt-patch/e420/org.eclipse.jdt.core/readme.txt @@ -1,3 +1,4 @@ 2021-04-09: 92041e1 (2021-06 M1) 2021-05-23: 8776058 (2021-06 M3) 2021-05-29: 1787e34 (2021-06 RC1) +2021-06-06: 0fc92c0 (2021-06 RC2) diff --git a/pom.xml b/pom.xml index 73ab7dda9c..c81a0c74a7 100644 --- a/pom.xml +++ b/pom.xml @@ -120,7 +120,7 @@ eclipse p2 - https://download.eclipse.org/eclipse/updates/4.20-I-builds/I20210526-2310 + https://download.eclipse.org/eclipse/updates/4.20-I-builds/I20210603-0040