Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt')
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest18.java204
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java6
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java41
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java38
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java92
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java69
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java105
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java27
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java177
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java257
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PackageBindingTest.java3
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerializableLambdaTest.java41
12 files changed, 1026 insertions, 34 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest18.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest18.java
index 852c395c4..01472ffab 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest18.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest18.java
@@ -17,6 +17,7 @@ import junit.framework.Test;
public class SelectionParserTest18 extends AbstractSelectionTest {
static {
// TESTS_NUMBERS = new int[] { 53 };
+// TESTS_NAMES = new String[] { "test495912" };
}
public static Test suite() {
return buildMinimalComplianceTestSuite(SelectionParserTest18.class, F_1_8);
@@ -249,4 +250,207 @@ public void test476693() throws JavaModelException {
expectedReplacedSource,
testName);
}
+public void test495912() {
+ String string =
+ "package xy;\n" +
+ "public class Test {\n" +
+ " {\n" +
+ " Runnable r = () -> {\n" +
+ " Integer i= 1;\n" +
+ " byte b= i.byteValue();\n" +
+ " if (true) {\n" +
+ " if (false) {\n" +
+ " }\n" +
+ " }\n" +
+ " String s= new String();\n" +
+ " };\n" +
+ " }\n" +
+ " public void foo(Runnable r) {\n" +
+ " }\n" +
+ "}";
+
+ String expectedCompletionNodeToString = "<SelectOnMessageSend:i.byteValue()>";
+
+ String completionIdentifier = "byteValue";
+ String expectedUnitDisplayString =
+ "package xy;\n" +
+ "public class Test {\n" +
+ " {\n" +
+ " Runnable r = () -> {\n" +
+ " Integer i;\n" +
+ " byte b = <SelectOnMessageSend:i.byteValue()>;\n" +
+ " if (true)\n" +
+ " {\n" +
+ " if (false)\n" +
+ " {\n" +
+ " }\n" +
+ " }\n" +
+ " String s;\n" +
+ " };\n" +
+ " }\n" +
+ " public Test() {\n" +
+ " }\n" +
+ " public void foo(Runnable r) {\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "i.byteValue()";
+ String testName = "<select>";
+
+ int selectionStart = string.indexOf("byteValue");
+ int selectionEnd = selectionStart + completionIdentifier.length() - 1;
+
+ this.checkMethodParse(
+ string.toCharArray(),
+ selectionStart,
+ selectionEnd,
+ expectedCompletionNodeToString,
+ expectedUnitDisplayString,
+ completionIdentifier,
+ expectedReplacedSource,
+ testName);
+}
+public void test495912a() {
+ String string =
+ "package xy;\n" +
+ "public class Test {\n" +
+ " {\n" +
+ " Runnable r = () -> {\n" +
+ " Integer i= 1;\n" +
+ " byte b= i.byteValue();\n" +
+ " if (true) {\n" +
+ " if (false) {\n" +
+ " }\n" +
+ " }\n" +
+ " for (int i1 = 0; i1 < 42; i1++) {\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ " public void foo(Runnable r) {\n" +
+ " }\n" +
+ "}";
+
+ String expectedCompletionNodeToString = "<SelectOnMessageSend:i.byteValue()>";
+
+ String completionIdentifier = "byteValue";
+ String expectedUnitDisplayString =
+ "package xy;\n" +
+ "public class Test {\n" +
+ " {\n" +
+ " Runnable r = () -> {\n" +
+ " Integer i;\n" +
+ " byte b = <SelectOnMessageSend:i.byteValue()>;\n" +
+ " if (true)\n" +
+ " {\n" +
+ " if (false)\n" +
+ " {\n" +
+ " }\n" +
+ " }\n" +
+ " for (int i1;; (i1 < 42); i1 ++) \n" +
+ " {\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ " public Test() {\n" +
+ " }\n" +
+ " public void foo(Runnable r) {\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "i.byteValue()";
+ String testName = "<select>";
+
+ int selectionStart = string.indexOf("byteValue");
+ int selectionEnd = selectionStart + completionIdentifier.length() - 1;
+
+ this.checkMethodParse(
+ string.toCharArray(),
+ selectionStart,
+ selectionEnd,
+ expectedCompletionNodeToString,
+ expectedUnitDisplayString,
+ completionIdentifier,
+ expectedReplacedSource,
+ testName);
+}
+public void test495912b() {
+ String string =
+ "package xy;\n" +
+ "import org.eclipse.e4.ui.internal.workbench.PartServiceImpl;\n" +
+ "import org.eclipse.e4.ui.model.application.ui.basic.MPart;\n" +
+ "import org.eclipse.swt.widgets.Table;\n" +
+ "import org.eclipse.ui.IWorkbenchWindow;\n" +
+ "public abstract class CycleViewHandler extends CycleBaseHandler {\n" +
+ " @Override\n" +
+ " protected void addItems(Table table, WorkbenchPage page) {\n" +
+ " List<MPart> parts = null;\n" +
+ " parts.stream().sorted((firstPart, secondPart) -> {\n" +
+ " Long firstPartActivationTime = (Long) firstPart.getTransientData()\n" +
+ " .getOrDefault(PartServiceImpl.PART_ACTIVATION_TIME, Long.MIN_VALUE);\n" +
+ " Long secondPartActivationTime = (Long) secondPart.getTransientData()\n" +
+ " .getOrDefault(PartServiceImpl.PART_ACTIVATION_TIME, Long.MIN_VALUE);\n" +
+ " return 0;\n" +
+ " }).forEach(part -> {\n" +
+ " if (true) {\n" +
+ " if (true) {\n" +
+ " }\n" +
+ " } \n" +
+ " else {\n" +
+ " IWorkbenchWindow iwbw = page.getWorkbenchWindow();\n" +
+ " if (true){\n" +
+ " }\n" +
+ " }\n" +
+ " });\n" +
+ " }\n" +
+ "}";
+
+ String expectedSelectionNodeToString = "<SelectOnMessageSend:firstPart.getTransientData()>";
+
+ String selectionIdentifier = "getTransientData";
+ String expectedUnitDisplayString =
+ "package xy;\n" +
+ "import org.eclipse.e4.ui.internal.workbench.PartServiceImpl;\n" +
+ "import org.eclipse.e4.ui.model.application.ui.basic.MPart;\n" +
+ "import org.eclipse.swt.widgets.Table;\n" +
+ "import org.eclipse.ui.IWorkbenchWindow;\n" +
+ "public abstract class CycleViewHandler extends CycleBaseHandler {\n" +
+ " public CycleViewHandler() {\n" +
+ " }\n" +
+ " protected @Override void addItems(Table table, WorkbenchPage page) {\n" +
+ " List<MPart> parts;\n" + // this is the missing part without the fix in RecoveredMethod#add(Block....)
+ " parts.stream().sorted((<no type> firstPart, <no type> secondPart) -> {\n" +
+ " Long firstPartActivationTime = (Long) <SelectOnMessageSend:firstPart.getTransientData()>.getOrDefault(PartServiceImpl.PART_ACTIVATION_TIME, Long.MIN_VALUE);\n" +
+ " Long secondPartActivationTime;\n" +
+ " return 0;\n" +
+ "}).forEach((<no type> part) -> {\n" +
+ " if (true)\n" +
+ " {\n" +
+ " if (true)\n" +
+ " {\n" +
+ " }\n" +
+ " }\n" +
+ " else\n" +
+ " {\n" +
+ " IWorkbenchWindow iwbw;\n" +
+ " if (true)\n" +
+ " {\n" +
+ " }\n" +
+ " }\n" +
+ "});\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "firstPart.getTransientData()";
+ String testName = "<select>";
+
+ int selectionStart = string.indexOf("getTransientData");
+ int selectionEnd = selectionStart + selectionIdentifier.length() - 1;
+
+ this.checkMethodParse(
+ string.toCharArray(),
+ selectionStart,
+ selectionEnd,
+ expectedSelectionNodeToString,
+ expectedUnitDisplayString,
+ selectionIdentifier,
+ expectedReplacedSource,
+ testName);
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
index 28b58aa92..fb9c9a273 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
@@ -395,7 +395,11 @@ protected static class JavacTestOptions {
}
} : null,
EclipseBug177715 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=177715
- new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) : null,
+ new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) {
+ Excuse excuseFor(JavacCompiler compiler) {
+ return compiler.compliance < ClassFileConstants.JDK1_8 ? this : null; // in 1.8 rejected by both compilers
+ }
+ } : null,
EclipseBug207935 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935
new EclipseHasABug(MismatchType.EclipseErrorsJavacNone | MismatchType.EclipseWarningsJavacNone) : null,
EclipseBug216558 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=216558
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java
index 7b65b81ec..41f359c00 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java
@@ -4362,24 +4362,29 @@ public void test086() {
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=321485
public void test087() {
- this.runNegativeTest(
- new String[] {
- "X.java",
- "import java.util.Collection;\n" +
- "import java.util.List;\n" +
- "public class X {\n" +
- " public static <T> List<T> with(List<? extends T> p) { return null; } \n" +
- " public static <T> Collection<T> with(Collection<T> p) { return null; }\n" +
- " static { with(null); }\n" +
- "} \n"
- },
- "----------\n" +
- "1. ERROR in X.java (at line 6)\n" +
- " static { with(null); }\n" +
- " ^^^^\n" +
- "The method with(List<? extends Object>) is ambiguous for the type X\n" +
- "----------\n"
- );
+ String source =
+ "import java.util.Collection;\n" +
+ "import java.util.List;\n" +
+ "public class X {\n" +
+ " public static <T> List<T> with(List<? extends T> p) { return null; } \n" +
+ " public static <T> Collection<T> with(Collection<T> p) { return null; }\n" +
+ " static { with(null); }\n" +
+ "} \n";
+ if (this.complianceLevel < ClassFileConstants.JDK1_8) {
+ this.runNegativeTest( // FIXME: Eclipse has a bug
+ new String[] { "X.java", source },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " static { with(null); }\n" +
+ " ^^^^\n" +
+ "The method with(List<? extends Object>) is ambiguous for the type X\n" +
+ "----------\n"
+ );
+ } else {
+ this.runConformTest(
+ new String[] { "X.java", source }
+ );
+ }
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=354579
public void test088a() {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
index 0d715eed9..ceba32ce8 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
@@ -29841,6 +29841,9 @@ public void test0909() {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583
public void test0910() {
+ int[] capIds = this.complianceLevel < ClassFileConstants.JDK1_8
+ ? new int[]{ 1, 3, 4, 6, 13}
+ : new int[]{ 1, 2, 3, 4, 8};
this.runNegativeTest(
new String[] {
"X.java",
@@ -29893,12 +29896,12 @@ public void test0910() {
"4. ERROR in X.java (at line 13)\n" +
" lc1 = lc3; //2 ko\n" +
" ^^^\n" +
- "Type mismatch: cannot convert from List<capture#1-of ? extends Collection<?>> to List<Collection>\n" +
+ "Type mismatch: cannot convert from List<capture#"+capIds[0]+"-of ? extends Collection<?>> to List<Collection>\n" +
"----------\n" +
"5. ERROR in X.java (at line 14)\n" +
" lc1 = lc4; //3 ko\n" +
" ^^^\n" +
- "Type mismatch: cannot convert from List<capture#3-of ? extends Collection> to List<Collection>\n" +
+ "Type mismatch: cannot convert from List<capture#"+capIds[1]+"-of ? extends Collection> to List<Collection>\n" +
"----------\n" +
"6. ERROR in X.java (at line 15)\n" +
" lc2 = lc1; //4 ko\n" +
@@ -29908,12 +29911,12 @@ public void test0910() {
"7. ERROR in X.java (at line 16)\n" +
" lc2 = lc3; //5 ko\n" +
" ^^^\n" +
- "Type mismatch: cannot convert from List<capture#4-of ? extends Collection<?>> to List<Collection<?>>\n" +
+ "Type mismatch: cannot convert from List<capture#"+capIds[2]+"-of ? extends Collection<?>> to List<Collection<?>>\n" +
"----------\n" +
"8. ERROR in X.java (at line 17)\n" +
" lc2 = lc4; //6 ko\n" +
" ^^^\n" +
- "Type mismatch: cannot convert from List<capture#6-of ? extends Collection> to List<Collection<?>>\n" +
+ "Type mismatch: cannot convert from List<capture#"+capIds[3]+"-of ? extends Collection> to List<Collection<?>>\n" +
"----------\n" +
"9. ERROR in X.java (at line 18)\n" +
" lc3 = lc1; //7 ko\n" +
@@ -29923,7 +29926,7 @@ public void test0910() {
"10. ERROR in X.java (at line 20)\n" +
" lc3 = lc4; //9 ko\n" +
" ^^^\n" +
- "Type mismatch: cannot convert from List<capture#13-of ? extends Collection> to List<? extends Collection<?>>\n" +
+ "Type mismatch: cannot convert from List<capture#"+capIds[4]+"-of ? extends Collection> to List<? extends Collection<?>>\n" +
"----------\n" +
"11. WARNING in X.java (at line 25)\n" +
" private final List<Collection> aList = new ArrayList<Collection>();\n" +
@@ -38756,11 +38759,7 @@ public void test1117() throws Exception {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177715
public void test1118() {
- runConformTest(
- // test directory preparation
- new String[] { /* test files */
- "X.java",
- "import java.util.List;\n" +
+ String source = "import java.util.List;\n" +
"\n" +
"public class X {\n" +
" X() {\n" +
@@ -38771,10 +38770,21 @@ public void test1118() {
" <I, T extends List<I>> T foo(Class<T> pClass) {\n" +
" return null;\n" +
" }\n" +
- "}\n", // =================
- },
- // javac options
- JavacTestOptions.EclipseHasABug.EclipseBug177715 /* javac test options */);
+ "}\n";
+ if (this.complianceLevel < ClassFileConstants.JDK1_8) {
+ runConformTest(
+ new String[] { "X.java", source },
+ JavacTestOptions.EclipseHasABug.EclipseBug177715 /* javac test options */);
+ } else {
+ runNegativeTest(
+ new String[] { "X.java", source },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " foo(cls);\n" +
+ " ^^^\n" +
+ "The method foo(Class<T>) in the type X is not applicable for the arguments (Class<capture#1-of ? extends List<?>>)\n" +
+ "----------\n");
+ }
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169728
public void test1119() {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
index 80a24af02..8375b7bda 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
@@ -5921,5 +5921,97 @@ public void testBug499048() {
"}\n"
});
}
+public void testBug499126() {
+ runConformTest(
+ new String[] {
+ "bug_ise_immutablelist/$Immutable.java",
+ "package bug_ise_immutablelist;\n" +
+ "\n" +
+ "public class $Immutable<T> {\n" +
+ "}\n" +
+ "",
+ "bug_ise_immutablelist/Test.java",
+ "package bug_ise_immutablelist;\n" +
+ "\n" +
+ "public class Test {\n" +
+ " public static $Immutable<Object> f;\n" +
+ "}\n" +
+ "",
+ }
+ );
+ runConformTest(
+ false,
+ new String[] {
+ "Usage.java",
+ "public class Usage {\n" +
+ " Object f() {return bug_ise_immutablelist.Test.f;}\n" +
+ "}\n" +
+ "",
+ },
+ null,
+ null,
+ null,
+ null
+ );
+}
+public void testBug441905() {
+ runConformTest(
+ new String[] {
+ "EclipseJava8Generics.java",
+ "import java.util.List;\n" +
+ "\n" +
+ "public class EclipseJava8Generics {\n" +
+ "\n" +
+ " public interface Foo<V> {\n" +
+ " }\n" +
+ "\n" +
+ " public static class FooBar<V, T extends Foo<V>> {\n" +
+ " }\n" +
+ "\n" +
+ " protected void doFoos(List<FooBar<?, ? extends Foo<?>>> fooBars) {\n" +
+ " FooBar<?, ? extends Foo<?>> fooBar = fooBars.iterator().next();\n" +
+ " doFoo(fooBar);\n" +
+ " }\n" +
+ "\n" +
+ " protected static <F> void doFoo(FooBar<F, ? extends Foo<F>> fooBar) {\n" +
+ " }\n" +
+ "\n" +
+ "}\n"
+ });
+}
+public void testBug469297() {
+ String source = " import java.util.List;\n" +
+ " \n" +
+ " public class Test {\n" +
+ " \n" +
+ " static final void a(Class<? extends List<?>> type) {\n" +
+ " b(newList(type));\n" +
+ " }\n" +
+ " \n" +
+ " static final <T> List<T> b(List<T> list) {\n" +
+ " return list;\n" +
+ " }\n" +
+ " \n" +
+ " static final <L extends List<?>> L newList(Class<L> type) {\n" +
+ " try {\n" +
+ " return type.newInstance();\n" +
+ " }\n" +
+ " catch (Exception e) {\n" +
+ " throw new RuntimeException(e);\n" +
+ " }\n" +
+ " }\n" +
+ " }\n";
+ if (this.complianceLevel < ClassFileConstants.JDK1_8) {
+ runConformTest(new String[] { "Test.java", source });
+ } else {
+ runNegativeTest(new String[] { "Test.java", source },
+ "----------\n" +
+ "1. ERROR in Test.java (at line 6)\n" +
+ " b(newList(type));\n" +
+ " ^\n" +
+ "The method b(List<T>) in the type Test is not applicable for the arguments (capture#1-of ? extends List<?>)\n" +
+ "----------\n");
+ }
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
index f25e40f5c..e53c45149 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
@@ -6886,4 +6886,73 @@ public void testBug497239() {
}
);
}
+public void testBug472851() {
+ runNegativeTest(
+ new String[] {
+ "Test.java",
+ "import java.util.*;\n" +
+ "\n" +
+ "public class Test {\n" +
+ " public static void main(String... arg) {\n" +
+ " List<Integer> l1=Arrays.asList(0, 1, 2);\n" +
+ " List<String> l2=Arrays.asList(\"0\", \"1\", \"2\");\n" +
+ " a(Arrays.asList(l1, l2));\n" +
+ "}\n" +
+ "static final void a(List<? extends List<?>> type) {\n" +
+ " test(type);\n" +
+ "}\n" +
+ "static final <Y,L extends List<Y>> void test(List<L> type) {\n" +
+ " L l1=type.get(0), l2=type.get(1);\n" +
+ " l2.set(0, l1.get(0));\n" +
+ "}\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in Test.java (at line 10)\n" +
+ " test(type);\n" +
+ " ^^^^\n" +
+ "The method test(List<L>) in the type Test is not applicable for the arguments (List<capture#1-of ? extends List<?>>)\n" +
+ "----------\n");
+}
+public void testBug502350() {
+ runNegativeTest(
+ new String[] {
+ "makeCompilerFreeze/EclipseJava8Bug.java",
+ "package makeCompilerFreeze;\n" +
+ "\n" +
+ "interface Comparable<E> {} \n" +
+ "\n" +
+ "interface Comparator<A> {\n" +
+ " public static <B extends Comparable<B>> Comparator<B> naturalOrder() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "\n" +
+ "class Stuff {\n" +
+ " public static <T, S extends T> Object func(Comparator<T> comparator) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "public class EclipseJava8Bug {\n" +
+ " static final Object BORKED =\n" +
+ " Stuff.func(Comparator.naturalOrder());\n" +
+ "}\n" +
+ "\n" +
+ "",
+ },
+ "----------\n" +
+ "1. ERROR in makeCompilerFreeze\\EclipseJava8Bug.java (at line 20)\n" +
+ " Stuff.func(Comparator.naturalOrder());\n" +
+ " ^^^^\n" +
+ "The method func(Comparator<T>) in the type Stuff is not applicable for the arguments (Comparator<Comparable<Comparable<B>>>)\n" +
+ "----------\n" +
+ "2. ERROR in makeCompilerFreeze\\EclipseJava8Bug.java (at line 20)\n" +
+ " Stuff.func(Comparator.naturalOrder());\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Type mismatch: cannot convert from Comparator<Comparable<Comparable<B>>> to Comparator<T>\n" +
+ "----------\n"
+ );
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
index 98d0c5fd5..74b2de1f0 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
@@ -6182,6 +6182,111 @@ public void test476859a() {
"private static java.lang.reflect.Method Test.lambda$0(java.lang.Void)\n" +
"private java.lang.reflect.Method AnotherClass.lambda$0(java.lang.Void)");
}
+public void testBug499258() {
+ runConformTest(
+ new String[] {
+ "bug499258/ShellTab.java",
+ "package bug499258;\n" +
+ "class Controller {\n" +
+ " public void newTerminal(Object... path) {\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "interface EventHandler {\n" +
+ " void handle();\n" +
+ "}\n" +
+ "\n" +
+ "public class ShellTab {\n" +
+ " private final Controller controller;\n" +
+ "\n" +
+ " public ShellTab(Controller controller) {\n" +
+ " this.controller = controller;\n" +
+ " EventHandler h = this.controller::newTerminal;\n" +
+ " }\n" +
+ "}\n" +
+ "",
+ }
+ );
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=500374 Using a method reference to a generic method in a Base class gives me NoSuchMethodError
+public void test500374() {
+ this.runConformTest(
+ new String[] {
+ "client/Client.java",
+ "package client;\n" +
+ "import lib.Sub;\n" +
+ "public class Client {\n" +
+ " public static void main(String[] args) throws Throwable {\n" +
+ " Sub s1 = new Sub();\n" +
+ " doSomething(() -> s1.m());\n" +
+ " doSomething(s1::m);\n" +
+ " }\n" +
+ " interface Aaa {\n" +
+ " Object f() throws Throwable;\n" +
+ " }\n" +
+ " public static void doSomething(Aaa a) throws Throwable {\n" +
+ " System.out.println(\"Done\");\n" +
+ " }\n" +
+ "}\n",
+ "lib/Sub.java",
+ "package lib;\n" +
+ "public class Sub extends Base<Sub> {}",
+ "lib/Base.java",
+ "package lib;\n" +
+ "class Base<T> {\n" +
+ " public T m() {\n" +
+ " System.out.println(\"m\");\n" +
+ " return thisInstance();\n" +
+ " }\n" +
+ " @SuppressWarnings(\"unchecked\")\n" +
+ " T thisInstance() {\n" +
+ " return (T) this;\n" +
+ " }\n" +
+ "}"
+ },
+ "Done\n" +
+ "Done");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=500374 Using a method reference to a generic method in a Base class gives me NoSuchMethodError
+public void test500374a() {
+ this.runConformTest(
+ new String[] {
+ "client/Client.java",
+ "package client;\n" +
+ "import java.lang.invoke.MethodHandle;\n" +
+ "import java.lang.invoke.MethodHandles;\n" +
+ "import java.lang.invoke.MethodType;\n" +
+ "import lib.Sub;\n" +
+ "public class Client {\n" +
+ " public static void main(String[] args) throws Throwable {\n" +
+ " MethodHandle mh = MethodHandles.lookup().findVirtual(Sub.class, \"m\", MethodType.methodType(Object.class));\n" +
+ " doSomething(mh::invoke);\n" +
+ " }\n" +
+ " interface Aaa {\n" +
+ " Object f() throws Throwable;\n" +
+ " }\n" +
+ " public static void doSomething(Aaa a) throws Throwable {\n" +
+ " System.out.println(\"Done\");\n" +
+ " }\n" +
+ "}\n",
+ "lib/Sub.java",
+ "package lib;\n" +
+ "public class Sub extends Base<Sub> {}",
+ "lib/Base.java",
+ "package lib;\n" +
+ "class Base<T> {\n" +
+ " public T m() {\n" +
+ " System.out.println(\"m\");\n" +
+ " return thisInstance();\n" +
+ " }\n" +
+ " @SuppressWarnings(\"unchecked\")\n" +
+ " T thisInstance() {\n" +
+ " return (T) this;\n" +
+ " }\n" +
+ "}"
+ },
+ "Done");
+}
public static Class testClass() {
return LambdaExpressionsTest.class;
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java
index 4f090c060..9e52dad32 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java
@@ -14300,4 +14300,31 @@ public void testBug467776_regression() {
},
compilerOptions);
}
+public void testBug500673() {
+ runNegativeTest(
+ new String[] {
+ "mfi.java",
+ "interface mfi {\n" +
+ " public transient void a(Throwable throwable);\n" +
+ "}\n",
+ "mfa.java",
+ "final class mfa implements mfi {\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in mfi.java (at line 2)\n" +
+ " public transient void a(Throwable throwable);\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^\n" +
+ (this.complianceLevel < ClassFileConstants.JDK1_8
+ ? "Illegal modifier for the interface method a; only public & abstract are permitted\n"
+ : "Illegal modifier for the interface method a; only public, abstract, default, static and strictfp are permitted\n"
+ ) +
+ "----------\n" +
+ "----------\n" +
+ "1. ERROR in mfa.java (at line 1)\n" +
+ " final class mfa implements mfi {\n" +
+ " ^^^\n" +
+ "The type mfa must implement the inherited abstract method mfi.a(Throwable)\n" +
+ "----------\n");
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
index 14d4d1960..d2c889178 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
@@ -17974,4 +17974,181 @@ public void testBug486912PotNullInLoop() {
"----------\n"
);
}
+public void testBug447695() {
+ runConformTest(
+ new String[] {
+ "test/Test447695.java",
+ "package test;\n" +
+ "\n" +
+ "public class Test447695 {\n" +
+ " public static void f() {\n" +
+ " int[] array = null;\n" +
+ " (array = new int[1])[0] = 42;\n" +
+ " }\n" +
+ " public static int g() {\n" +
+ " int[] array = null;\n" +
+ " return (array = new int[1])[0];\n" +
+ " }\n" +
+ "}\n"
+ }
+ );
+}
+public void testBug447695b() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses foreach
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.*;\n" +
+ "public class X {\n" +
+ " void test(String[] ss) {\n" +
+ " List<String> strings = null;\n" +
+ " for (String s : (strings = Arrays.asList(ss)))\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ "}\n"
+ });
+}
+public void testBug447695c() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses autoboxing
+ runConformTest(
+ new String[] {
+ "test/Test447695.java",
+ "package test;\n" +
+ "\n" +
+ "public class Test447695 {\n" +
+ " void f() {\n" +
+ " Integer l1 = null;\n" +
+ " Integer l2 = null;\n" +
+ " int b = (l1 = new Integer(2)) + (l2 = new Integer(1));\n" +
+ " }\n" +
+ "}\n"
+ }
+ );
+}
+public void testBug447695d() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // uses reference expression
+ runConformTest(
+ new String[] {
+ "test/Test447695.java",
+ "package test;\n" +
+ "\n" +
+ "import java.util.function.Supplier;\n" +
+ "\n" +
+ "public class Test447695 {\n" +
+ " void f() {\n" +
+ " String s = null;\n" +
+ " Supplier<String> l = (s = \"\")::toString;\n" +
+ " }\n" +
+ "}\n"
+ }
+ );
+}
+public void testBug447695e() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses autoboxing
+ runConformTest(
+ new String[] {
+ "test/Test447695.java",
+ "package test;\n" +
+ "\n" +
+ "public class Test447695 {\n" +
+ " void f() {\n" +
+ " Integer i = null;\n" +
+ " int j = -(i = new Integer(1));\n" +
+ " Boolean b1 = null;\n" +
+ " boolean b = !(b1 = new Boolean(false));\n" +
+ " }\n" +
+ "}\n"
+ }
+ );
+}
+public void testBug447695f() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses autoboxing
+ runConformTest(
+ new String[] {
+ "test/Test447695.java",
+ "package test;\n" +
+ "\n" +
+ "public class Test447695 {\n" +
+ " void f() {\n" +
+ " int i = 0;\n" +
+ " Integer i1 = null;\n" +
+ " Integer i2 = null;\n" +
+ " Integer i3 = null;\n" +
+ " int j = (i1 = new Integer(1)) \n" +
+ " + (i2 = new Integer(1)) \n" +
+ " + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i \n" +
+ " + (i3 = new Integer(2)) + i;\n" +
+ " }\n" +
+ "}\n"
+ }
+ );
+}
+public void testBug447695g() {
+ runNegativeTest(
+ new String[] {
+ "test/Test447695.java",
+ "package test;\n" +
+ "\n" +
+ "class X {\n" +
+ " int i;\n" +
+ "}\n" +
+ "\n" +
+ "public class Test447695 {\n" +
+ " void f() {\n" +
+ " X x1 = null;\n" +
+ " X x2 = null;\n" +
+ " X x3 = null;\n" +
+ " X x4 = null;\n" +
+ " X x5 = null;\n" +
+ " X x6 = null;\n" +
+ " X x7 = null;\n" +
+ " X x8 = null;\n" +
+ " X x9 = null;\n" +
+ " X x10 = null;\n" +
+ " X x11 = null;\n" +
+ " x1.i = 1; // error 1 expected\n" +
+ " x2.i += 1; // error 2 expected\n" +
+ " (x3).i = 1; // error 3 expected\n" +
+ " (x4).i += 1; // error 4 expected\n" +
+ " (x5 = new X()).i = (x6 = new X()).i;\n" +
+ " (x7 = new X()).i += (x8 = new X()).i;\n" +
+ " int i1 = x9.i; // error 5 expected\n" +
+ " int i2 = (x10).i; // error 6 expected\n" +
+ " int i3 = (x11 = new X()).i;\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in test\\Test447695.java (at line 20)\n" +
+ " x1.i = 1; // error 1 expected\n" +
+ " ^^\n" +
+ "Null pointer access: The variable x1 can only be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in test\\Test447695.java (at line 21)\n" +
+ " x2.i += 1; // error 2 expected\n" +
+ " ^^\n" +
+ "Null pointer access: The variable x2 can only be null at this location\n" +
+ "----------\n" +
+ "3. ERROR in test\\Test447695.java (at line 22)\n" +
+ " (x3).i = 1; // error 3 expected\n" +
+ " ^^^^\n" +
+ "Null pointer access: The variable x3 can only be null at this location\n" +
+ "----------\n" +
+ "4. ERROR in test\\Test447695.java (at line 23)\n" +
+ " (x4).i += 1; // error 4 expected\n" +
+ " ^^^^\n" +
+ "Null pointer access: The variable x4 can only be null at this location\n" +
+ "----------\n" +
+ "5. ERROR in test\\Test447695.java (at line 26)\n" +
+ " int i1 = x9.i; // error 5 expected\n" +
+ " ^^\n" +
+ "Null pointer access: The variable x9 can only be null at this location\n" +
+ "----------\n" +
+ "6. ERROR in test\\Test447695.java (at line 27)\n" +
+ " int i2 = (x10).i; // error 6 expected\n" +
+ " ^^^^^\n" +
+ "Null pointer access: The variable x10 can only be null at this location\n" +
+ "----------\n"
+ );
+}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
index 5db5078e2..4cb5285dc 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
@@ -12226,6 +12226,101 @@ public void testBug489245() {
"----------\n"
);
}
+public void testBug489674() {
+ Map options = new HashMap<>(getCompilerOptions());
+ options.put(JavaCore.COMPILER_NONNULL_ANNOTATION_SECONDARY_NAMES, "org.foo.NonNull");
+ options.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_SECONDARY_NAMES, "org.foo.Nullable");
+ runConformTest(
+ new String[] {
+ "org/foo/Nullable.java",
+ "package org.foo;\n" +
+ "import java.lang.annotation.*;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "@Retention(RetentionPolicy.CLASS)\n" +
+ "@Target({ FIELD, METHOD, PARAMETER, LOCAL_VARIABLE })\n" +
+ "public @interface Nullable {}\n",
+ "org/foo/NonNull.java",
+ "package org.foo;\n" +
+ "import java.lang.annotation.*;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "@Retention(RetentionPolicy.CLASS)\n" +
+ "@Target({ FIELD, METHOD, PARAMETER, LOCAL_VARIABLE })\n" +
+ "public @interface NonNull {}\n",
+ "}"
+ },
+ options);
+ runConformTestWithLibs(
+ new String[] {
+ "with_other_nullable/P1.java",
+ "package with_other_nullable;\n" +
+ "\n" +
+ "import org.foo.Nullable;\n" +
+ "\n" +
+ "public class P1 {\n" +
+ " public static @Nullable String f0() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "\n" +
+ " public static <T> T check(T t) {\n" +
+ " return t;\n" +
+ " }\n" +
+ "}\n" +
+ "",
+ "with_other_nullable/P2.java",
+ "package with_other_nullable;\n" +
+ "\n" +
+ "import org.foo.NonNull;\n" +
+ "\n" +
+ "public class P2 {\n" +
+ " public static void f(@NonNull String s) {\n" +
+ " }\n" +
+ "\n" +
+ " public static <T> T check(T t) {\n" +
+ " return t;\n" +
+ " }\n" +
+ "}\n" +
+ "",
+ },
+ options,
+ ""
+ );
+ runNegativeTestWithLibs(
+ new String[] {
+ "test/Test4.java",
+ "package test;\n" +
+ "\n" +
+ "import org.eclipse.jdt.annotation.NonNullByDefault;\n" +
+ "\n" +
+ "import with_other_nullable.P1;\n" +
+ "import with_other_nullable.P2;\n" +
+ "\n" +
+ "@NonNullByDefault\n" +
+ "public class Test4 {\n" +
+ " void m1(String s) {\n" +
+ " P1.f0().hashCode();\n" +
+ " s = P1.check(s);\n" +
+ " }\n" +
+ " void m2(String s) {\n" +
+ " P2.f(null);\n" +
+ " s = P2.check(s);\n" +
+ " }\n" +
+ "}\n" +
+ "",
+ },
+ options,
+ "----------\n" +
+ "1. ERROR in test\\Test4.java (at line 11)\n" +
+ " P1.f0().hashCode();\n" +
+ " ^^^^^^^\n" +
+ "Potential null pointer access: The method f0() may return null\n" +
+ "----------\n" +
+ "2. ERROR in test\\Test4.java (at line 15)\n" +
+ " P2.f(null);\n" +
+ " ^^^^\n" +
+ "Null type mismatch: required \'String\' but the provided value is null\n" +
+ "----------\n"
+ );
+}
public void testBug492327() {
runConformTestWithLibs(
new String[] {
@@ -12651,4 +12746,166 @@ public void testBug492322withGenericBase() {
""
);
}
+public void testBug499862a() {
+ runConformTestWithLibs(
+ new String[] {
+ "Test.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " static void printChecked(Collection<? extends @Nullable String> collection) {\n" +
+ " for(String s : collection)\n" +
+ " if (s != null)\n" +
+ " System.out.println(s.toString());\n" +
+ " else\n" +
+ " System.out.println(\"NULL\");\n" +
+ " }\n" +
+ "}\n"
+ },
+ getCompilerOptions(),
+ "");
+}
+public void testBug499862b() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "Test.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " static void printChecked(Collection<? extends @Nullable String> collection) {\n" +
+ " for(String s : collection)\n" +
+ " System.out.println(s.toString());\n" +
+ " }\n" +
+ "}\n"
+ },
+ getCompilerOptions(),
+ "----------\n" +
+ "1. ERROR in Test.java (at line 6)\n" +
+ " System.out.println(s.toString());\n" +
+ " ^\n" +
+ "Potential null pointer access: The variable s may be null at this location\n" +
+ "----------\n");
+}
+public void testBug499862c() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "Test.java",
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " static <T> void printUnchecked(Collection<T> collection) {\n" +
+ " for(T t : collection)\n" +
+ " System.out.println(t.toString());\n" +
+ " }\n" +
+ "}\n"
+ },
+ getCompilerOptions(),
+ "----------\n" +
+ "1. ERROR in Test.java (at line 5)\n" +
+ " System.out.println(t.toString());\n" +
+ " ^\n" +
+ "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" +
+ "----------\n");
+}
+public void testBug499597simplified() {
+ runConformTestWithLibs(
+ new String[] {
+ "Foo2.java",
+ "import org.eclipse.jdt.annotation.NonNull;\n" +
+ "import org.eclipse.jdt.annotation.NonNullByDefault;\n" +
+ "\n" +
+ "@NonNullByDefault\n" +
+ "class Foo2 {\n" +
+ " static <T> T of(T t) {\n" +
+ " return t;\n" +
+ " }\n" +
+ "\n" +
+ " static String foo() {\n" +
+ " return Foo2.<String>of(\"\"); // <-- warning here\n" +
+ " }\n" +
+ "\n" +
+ " static String bar() {\n" +
+ " return Foo2.<@NonNull String>of(\"\"); // <-- no warning\n" +
+ " }\n" +
+ "}\n" +
+ "",
+ },
+ getCompilerOptions(),
+ ""
+ );
+}
+public void testBug499597original() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "Foo.java",
+ "import static org.eclipse.jdt.annotation.DefaultLocation.*;\n" +
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "\n" +
+ "import java.util.Collection;\n" +
+ "import java.util.Collections;\n" +
+ "\n" +
+ "class Foo {\n" +
+ " static @NonNull String @NonNull [] X = { \"A\" };\n" +
+ "\n" +
+ " @NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS })\n" +
+ " @SafeVarargs\n" +
+ " static <T> Collection<T> of(@NonNull T @NonNull... elements) {\n" +
+ " return Collections.singleton(elements[0]);\n" +
+ " }\n" +
+ "\n" +
+ " @NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS })\n" +
+ " static Collection<String[]> foo() {\n" +
+ " return Foo.<String[]>of(X); // <-- warning here\n" +
+ " }\n" +
+ "\n" +
+ " @NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS })\n" +
+ " static Collection<String[]> bar() {\n" +
+ " return Foo.<String @NonNull []>of(X); // <-- no warning\n" +
+ " }\n" +
+ "}\n" +
+ "",
+ },
+ getCompilerOptions(),
+ "----------\n" +
+ "1. WARNING in Foo.java (at line 12)\n" +
+ " static <T> Collection<T> of(@NonNull T @NonNull... elements) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The nullness annotation is redundant with a default that applies to this location\n" +
+ "----------\n" +
+ "2. WARNING in Foo.java (at line 13)\n" +
+ " return Collections.singleton(elements[0]);\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Null type safety (type annotations): The expression of type \'Set<T>\' needs unchecked conversion to conform to \'@NonNull Collection<T>\', corresponding supertype is \'Collection<T>\'\n" +
+ "----------\n"
+ );
+}
+public void testBug501449() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "Test.java",
+ "import org.eclipse.jdt.annotation.Nullable;\n" +
+ "\n" +
+ "public class Test {\n" +
+ " <T, S extends T> void f(T[] objects, @Nullable T nullableValue, T value, S subclassValue) {\n" +
+ " objects[0] = null;\n" +
+ " objects[1] = nullableValue;\n" +
+ " objects[2] = value;\n" +
+ " objects[3] = subclassValue;\n" +
+ " }\n" +
+ "}\n" +
+ "",
+ },
+ getCompilerOptions(),
+ "----------\n" +
+ "1. ERROR in Test.java (at line 5)\n" +
+ " objects[0] = null;\n" +
+ " ^^^^^^^^^^\n" +
+ "Null type mismatch (type annotations): \'null\' is not compatible to the free type variable \'T\'\n" +
+ "----------\n" +
+ "2. ERROR in Test.java (at line 6)\n" +
+ " objects[1] = nullableValue;\n" +
+ " ^^^^^^^^^^\n" +
+ "Null type mismatch (type annotations): required \'T\' but this expression has type \'@Nullable T\', where \'T\' is a free type variable\n" +
+ "----------\n"
+ );
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PackageBindingTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PackageBindingTest.java
index 827e53d39..f848e19c0 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PackageBindingTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PackageBindingTest.java
@@ -29,8 +29,9 @@ public class PackageBindingTest extends AbstractCompilerTest
/**
* This test checks if it is searched for packages before searching for types.
* The search for packages is much faster than searching for types, therefore it should get executed before searching for types.
+ * Commented since reverted to original behaviour as per bug 495598
*/
- public void test01() {
+ public void _test01() {
NameEnvironmentDummy nameEnv = new NameEnvironmentDummy(true);
PackageBinding packageBinding = new PackageBinding(new LookupEnvironment(null, new CompilerOptions(), null, nameEnv));
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerializableLambdaTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerializableLambdaTest.java
index 18e554d21..30541d602 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerializableLambdaTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerializableLambdaTest.java
@@ -2158,6 +2158,47 @@ public class SerializableLambdaTest extends AbstractRegressionTest {
null,true,
new String[]{"-Ddummy"});
}
+ public void testbug503118() {
+ this.runConformTest(
+ new String[]{
+ "lambdabug/App.java",
+ "package lambdabug;\n" +
+ "import java.io.ByteArrayInputStream;\n" +
+ "import java.io.ByteArrayOutputStream;\n" +
+ "import java.io.ObjectInputStream;\n" +
+ "import java.io.ObjectOutputStream;\n" +
+ "import java.io.Serializable;\n" +
+ "import java.util.function.Function;\n" +
+ "public class App {\n" +
+ " public static interface SerialFunction<T, R> extends Function<T, R>, Serializable {\n" +
+ " }\n" +
+ " public static interface TestInterface extends Serializable {\n" +
+ " public Integer method(Integer i);\n" +
+ " }\n" +
+ " public static class TestClass implements TestInterface {\n" +
+ " private static final long serialVersionUID = 1L;\n" +
+ " @Override\n" +
+ " public Integer method(Integer i) {\n" +
+ " return i;\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) throws Exception {\n" +
+ " TestInterface testService = getService();\n" +
+ " SerialFunction<Integer, Integer> sf = testService::method;\n" +
+ " ByteArrayOutputStream bos = new ByteArrayOutputStream();\n" +
+ " new ObjectOutputStream(bos).writeObject(sf);\n" +
+ " Object o = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())).readObject();\n" +
+ " System.out.println(o.getClass().getInterfaces()[0]);\n" +
+ " }\n" +
+ " private static TestInterface getService() {\n" +
+ " return new TestClass();\n" +
+ " }\n" +
+ "}\n"
+ },
+ "interface lambdabug.App$SerialFunction",
+ null,true,
+ new String[]{"-Ddummy"});
+ }
// ---
private void checkExpected(String expected, String actual) {

Back to the top