update jdt.core to I20200129-1800 for 2020-03 M2
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
index 195dc75..07359c9 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -1067,7 +1067,8 @@
" <option key=\"org.eclipse.jdt.core.compiler.emulateJavacBug8031744\" value=\"enabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.generateClassFiles\" value=\"enabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.maxProblemPerUnit\" value=\"100\"/>\n" +
- " <option key=\"org.eclipse.jdt.core.compiler.problem.APILeak\" value=\"warning\"/>\n" +
+ " <option key=\"org.eclipse.jdt.core.compiler.problem.APILeak\" value=\"warning\"/>\n" +
+ " <option key=\"org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated\" value=\"info\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.annotationSuperInterface\" value=\"warning\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.assertIdentifier\" value=\"warning\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.autoboxing\" value=\"ignore\"/>\n" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
index 401638e..393c565 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
@@ -344,6 +344,8 @@
expectedProblemAttributes.put("AmbiguousField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("AmbiguousMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("AmbiguousType", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
+ expectedProblemAttributes.put("AnnotatedTypeArgumentToUnannotated", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
+ expectedProblemAttributes.put("AnnotatedTypeArgumentToUnannotatedSuperHint", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("AnnotationCannotOverrideMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("AnnotationCircularity", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("AnnotationCircularitySelfReference", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
@@ -1414,6 +1416,8 @@
expectedProblemAttributes.put("AmbiguousField", SKIP);
expectedProblemAttributes.put("AmbiguousMethod", SKIP);
expectedProblemAttributes.put("AmbiguousType", SKIP);
+ expectedProblemAttributes.put("AnnotatedTypeArgumentToUnannotated", new ProblemAttributes(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED));
+ expectedProblemAttributes.put("AnnotatedTypeArgumentToUnannotatedSuperHint", new ProblemAttributes(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED));
expectedProblemAttributes.put("AnnotationCannotOverrideMethod", SKIP);
expectedProblemAttributes.put("AnnotationCircularity", SKIP);
expectedProblemAttributes.put("AnnotationCircularitySelfReference", SKIP);
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 65a5618..376e4b3 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
@@ -10041,4 +10041,23 @@
runner.runConformTest(); // don't use pre-compiled p/X$1.class
}
+ public void testBug559449() {
+ Runner runner = new Runner();
+ runner.testFiles = new String[] {
+ "p/X.java",
+ "package p;\n" +
+ "public class X {\n" +
+ " class $$$ {}\n" +
+ " <S> void m() {\n" +
+ " Runnable r = () -> {\n" +
+ " $$$ ddd = new $$$();\n" +
+ " if (ddd != null)\n" +
+ " System.out.println(ddd);\n" +
+ " };\n" +
+ " r.run();\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.runConformTest();
+ }
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
index 2f147da..98f0312 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
@@ -8290,7 +8290,7 @@
?
" @NonNull MyEnum[] getValues() {\n"
:
- " MyEnum @NonNull[] getValues() {\n"
+ " @NonNull MyEnum @NonNull[] getValues() {\n"
)+
" return MyEnum.values();\n" +
" }\n" +
@@ -8326,7 +8326,7 @@
?
" @NonNull MyEnum[] getValues() {\n"
:
- " MyEnum @NonNull[] getValues() {\n"
+ " @NonNull MyEnum @NonNull[] getValues() {\n"
)+
" return MyEnum.values();\n" +
" }\n" +
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 c6e8637..a2d4457 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2019 GK Software AG and others.
+ * Copyright (c) 2012, 2020 GK Software AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -827,6 +827,8 @@
// issue from https://bugs.eclipse.org/bugs/show_bug.cgi?id=403216#c7
public void testBug403216_2() {
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.IGNORE);
runConformTestWithLibs(
new String[] {
"X.java",
@@ -839,7 +841,7 @@
" }\n" +
"}\n"
},
- getCompilerOptions(),
+ options,
"");
}
@@ -1451,7 +1453,7 @@
"3. ERROR in Y1.java (at line 11)\n" +
" x.wildcard1(new ArrayList<@NonNull X1>()); // incompatible\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'List<@Nullable ? extends X1>\' but this expression has type \'ArrayList<@NonNull X1>\', corresponding supertype is \'List<@NonNull X1>\'\n" +
+ "Null type mismatch (type annotations): required \'List<@Nullable ? extends X1>\' but this expression has type \'@NonNull ArrayList<@NonNull X1>\', corresponding supertype is \'List<@NonNull X1>\'\n" +
"----------\n");
}
@@ -1531,7 +1533,7 @@
"3. ERROR in Y1.java (at line 11)\n" +
" x.wildcard1(new ArrayList<p.@NonNull X1>()); // incompatible\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'List<@Nullable ? extends X1>\' but this expression has type \'ArrayList<@NonNull X1>\', corresponding supertype is \'List<@NonNull X1>\'\n" +
+ "Null type mismatch (type annotations): required \'List<@Nullable ? extends X1>\' but this expression has type \'@NonNull ArrayList<@NonNull X1>\', corresponding supertype is \'List<@NonNull X1>\'\n" +
"----------\n");
}
@@ -1829,6 +1831,8 @@
// types with null annotations on details (type parameter) are compatible to types lacking the annotation
public void testCompatibility2() {
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.IGNORE);
runConformTestWithLibs(
new String[] {
"X.java",
@@ -1857,7 +1861,7 @@
+ " void takeAny(List<String> any) {}\n"
+ "}\n"
},
- getCompilerOptions(),
+ options,
"");
}
@@ -3124,7 +3128,7 @@
"1. WARNING in X.java (at line 8)\n" +
" List<@NonNull ? extends @NonNull String> ls = new ArrayList<String>();\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type safety (type annotations): The expression of type \'ArrayList<String>\' needs unchecked conversion to conform to \'List<@NonNull ? extends @NonNull String>\', corresponding supertype is 'List<String>'\n" +
+ "Null type safety (type annotations): The expression of type \'@NonNull ArrayList<String>\' needs unchecked conversion to conform to \'List<@NonNull ? extends @NonNull String>\', corresponding supertype is 'List<String>'\n" +
"----------\n" +
"2. ERROR in X.java (at line 9)\n" +
" ls.add(null);\n" +
@@ -3255,7 +3259,12 @@
"}\n"
},
getCompilerOptions(),
- "");
+ "----------\n" +
+ "1. INFO in X.java (at line 9)\n" +
+ " X<String> x = new Y();\n" +
+ " ^^^^^^^\n" +
+ "Unsafe null type conversion (type annotations): The value of type '@NonNull Y' is made accessible using the less-annotated type 'X<String>', corresponding supertype is 'X<@NonNull String>'\n" +
+ "----------\n");
}
public void testBug416181() {
@@ -3317,7 +3326,7 @@
"1. WARNING in X.java (at line 9)\n" +
" X<@Nullable String> xs = new X<String>();\n" +
" ^^^^^^^^^^^^^^^\n" +
- "Null type safety (type annotations): The expression of type \'X<String>\' needs unchecked conversion to conform to \'X<@Nullable String>\'\n" +
+ "Null type safety (type annotations): The expression of type \'@NonNull X<String>\' needs unchecked conversion to conform to \'X<@Nullable String>\'\n" +
"----------\n" +
"2. ERROR in X.java (at line 10)\n" +
" xs.foo(null);\n" +
@@ -3363,7 +3372,7 @@
"1. WARNING in X.java (at line 10)\n" +
" X<@Nullable String> xs = new X<String>();\n" +
" ^^^^^^^^^^^^^^^\n" +
- "Null type safety (type annotations): The expression of type \'X<String>\' needs unchecked conversion to conform to \'X<@Nullable String>\'\n" +
+ "Null type safety (type annotations): The expression of type \'@NonNull X<String>\' needs unchecked conversion to conform to \'X<@Nullable String>\'\n" +
"----------\n" +
"2. ERROR in X.java (at line 12)\n" +
" xs.foo(null);\n" +
@@ -3466,7 +3475,7 @@
"2. WARNING in X.java (at line 10)\n" +
" s.foo(new ArrayList<String>()); // (1)\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type safety (type annotations): The expression of type \'ArrayList<String>\' needs unchecked conversion to conform to \'@NonNull List<@NonNull String>\', corresponding supertype is 'List<String>'\n" +
+ "Null type safety (type annotations): The expression of type \'@NonNull ArrayList<String>\' needs unchecked conversion to conform to \'@NonNull List<@NonNull String>\', corresponding supertype is 'List<String>'\n" +
"----------\n" +
"3. ERROR in X.java (at line 11)\n" +
" s.foo(null); // (2)\n" +
@@ -3667,12 +3676,17 @@
" ^^^^\n" +
"Null type mismatch: required \'@NonNull String\' but the provided value is null\n" +
"----------\n" +
- "2. ERROR in X.java (at line 7)\n" +
+ "2. INFO in X.java (at line 7)\n" +
+ " @NonNull String @NonNull [][] s2 = new @NonNull String [] @NonNull [] { null, { null} }; // problem at both nulls\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Unsafe null type conversion (type annotations): The value of type \'@NonNull String [] @NonNull[]\' is made accessible using the less-annotated type \'@NonNull String @NonNull[] []\'\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 7)\n" +
" @NonNull String @NonNull [][] s2 = new @NonNull String [] @NonNull [] { null, { null} }; // problem at both nulls\n" +
" ^^^^\n" +
"Null type mismatch: required \'@NonNull String @NonNull[]\' but the provided value is null\n" +
"----------\n" +
- "3. ERROR in X.java (at line 7)\n" +
+ "4. ERROR in X.java (at line 7)\n" +
" @NonNull String @NonNull [][] s2 = new @NonNull String [] @NonNull [] { null, { null} }; // problem at both nulls\n" +
" ^^^^\n" +
"Null type mismatch: required \'@NonNull String\' but the provided value is null\n" +
@@ -3682,6 +3696,8 @@
// https://bugs.eclipse.org/417758 - [1.8][null] Null safety compromise during array creation.
// three-dim array with annotations on dimensions, also assignment has a problem
public void testArray3() {
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.WARNING);
runNegativeTestWithLibs(
new String[] {
"X.java",
@@ -3694,12 +3710,12 @@
" }\n" +
"}"
},
- getCompilerOptions(),
+ options,
"----------\n" +
"1. WARNING in X.java (at line 6)\n" +
" @NonNull String [][] @NonNull [] s = new @NonNull String []@NonNull [][] { null, { {null}, null/*ok*/ } };\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type safety (type annotations): The expression of type \'@NonNull String [] @NonNull[] []\' needs unchecked conversion to conform to \'@NonNull String [] [] @NonNull[]\'\n" +
+ "Unsafe null type conversion (type annotations): The value of type \'@NonNull String [] @NonNull[] []\' is made accessible using the less-annotated type \'@NonNull String [] [] @NonNull[]\'\n" +
"----------\n" +
"2. ERROR in X.java (at line 6)\n" +
" @NonNull String [][] @NonNull [] s = new @NonNull String []@NonNull [][] { null, { {null}, null/*ok*/ } };\n" +
@@ -4710,7 +4726,7 @@
"1. ERROR in X.java (at line 5)\n" +
" List<@NonNull Person> l = new ArrayList<@Nullable Person>();}\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'List<@NonNull Person>\' but this expression has type \'ArrayList<@Nullable Person>\', corresponding supertype is \'List<@Nullable Person>\'\n" +
+ "Null type mismatch (type annotations): required \'List<@NonNull Person>\' but this expression has type \'@NonNull ArrayList<@Nullable Person>\', corresponding supertype is \'List<@Nullable Person>\'\n" +
"----------\n");
}
public void testBug430219() {
@@ -4777,7 +4793,7 @@
"2. ERROR in X.java (at line 7)\n" +
" return new ArrayList<@Nullable Number>(); // ERR\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'List<@NonNull Number>\' but this expression has type \'ArrayList<@Nullable Number>\', corresponding supertype is \'List<@Nullable Number>\'\n" +
+ "Null type mismatch (type annotations): required \'List<@NonNull Number>\' but this expression has type \'@NonNull ArrayList<@Nullable Number>\', corresponding supertype is \'List<@Nullable Number>\'\n" +
"----------\n" +
"3. ERROR in X.java (at line 10)\n" +
" in.add(null); // ERR\n" +
@@ -4787,7 +4803,7 @@
"4. ERROR in X.java (at line 11)\n" +
" return new ArrayList<java.lang.@Nullable Number>(); // ERR\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'List<@NonNull Number>\' but this expression has type \'ArrayList<@Nullable Number>\', corresponding supertype is \'List<@Nullable Number>\'\n" +
+ "Null type mismatch (type annotations): required \'List<@NonNull Number>\' but this expression has type \'@NonNull ArrayList<@Nullable Number>\', corresponding supertype is \'List<@Nullable Number>\'\n" +
"----------\n");
}
@@ -4823,7 +4839,7 @@
"3. ERROR in X.java (at line 8)\n" +
" return new ArrayList<@Nullable T>(); // NOK, cannot assume nullable for T in List<T>\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'List<T>\' but this expression has type \'ArrayList<@Nullable T>\', corresponding supertype is \'List<@Nullable T>\'\n" +
+ "Null type mismatch (type annotations): required \'List<T>\' but this expression has type \'@NonNull ArrayList<@Nullable T>\', corresponding supertype is \'List<@Nullable T>\'\n" +
"----------\n");
}
@@ -5129,7 +5145,7 @@
"4. ERROR in X.java (at line 13)\n" +
" @NonNull Number nnn = inner.process(Integer.valueOf(3), new ArrayList<@Nullable Integer>()); // WARN on 1. arg; ERR on 2. arg\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'List<? extends @NonNull Number>\' but this expression has type \'ArrayList<@Nullable Integer>\', corresponding supertype is \'List<@Nullable Integer>\'\n" +
+ "Null type mismatch (type annotations): required \'List<? extends @NonNull Number>\' but this expression has type \'@NonNull ArrayList<@Nullable Integer>\', corresponding supertype is \'List<@Nullable Integer>\'\n" +
"----------\n");
}
@@ -5170,7 +5186,7 @@
"1. ERROR in Y.java (at line 5)\n" +
" x.test1(new ArrayList<@Nullable Number>()) // ERR at arg\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'List<@NonNull Number>\' but this expression has type \'ArrayList<@Nullable Number>\', corresponding supertype is \'List<@Nullable Number>\'\n" +
+ "Null type mismatch (type annotations): required \'List<@NonNull Number>\' but this expression has type \'@NonNull ArrayList<@Nullable Number>\', corresponding supertype is \'List<@Nullable Number>\'\n" +
"----------\n" +
"2. ERROR in Y.java (at line 6)\n" +
" .add(null); // ERR\n" +
@@ -5410,7 +5426,7 @@
"2. ERROR in Y.java (at line 5)\n" +
" @NonNull Number nnn = inner.process(Integer.valueOf(3), new ArrayList<@Nullable Integer>()); // WARN on 1. arg; ERR on 2. arg\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'List<? extends @NonNull Number>\' but this expression has type \'ArrayList<@Nullable Integer>\', corresponding supertype is \'List<@Nullable Integer>\'\n" +
+ "Null type mismatch (type annotations): required \'List<? extends @NonNull Number>\' but this expression has type \'@NonNull ArrayList<@Nullable Integer>\', corresponding supertype is \'List<@Nullable Integer>\'\n" +
"----------\n");
}
public void testBug431269() {
@@ -6620,7 +6636,12 @@
"}\n"
},
getCompilerOptions(),
- "");
+ "----------\n" +
+ "1. INFO in Extract.java (at line 9)\n" +
+ " return new R<@NonNull A>(null);\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Unsafe null type conversion (type annotations): The value of type '@NonNull R<@NonNull A>' is made accessible using the less-annotated type 'R<A>'\n" +
+ "----------\n");
}
public void testBug439298_comment4() {
runConformTestWithLibs(
@@ -8160,7 +8181,7 @@
"1. ERROR in X.java (at line 8)\n" +
" return zork(new FI<>());\n" +
" ^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'F0<@NonNull String>\' but this expression has type \'FI<@Nullable String>\', corresponding supertype is \'F0<@Nullable String>\'\n" +
+ "Null type mismatch (type annotations): required \'F0<@NonNull String>\' but this expression has type \'@NonNull FI<@Nullable String>\', corresponding supertype is \'F0<@Nullable String>\'\n" +
"----------\n");
}
public void testBug448709_allocationExpression2() {
@@ -11983,7 +12004,7 @@
"12. WARNING in nonnull\\WildcardNonNullTest.java (at line 81)\n" +
" g(new A<T2>());\n" +
" ^^^^^^^^^^^\n" +
- "Null type safety (type annotations): The expression of type \'A<T2>\' needs unchecked conversion to conform to \'@NonNull A<@NonNull T2>\'\n" +
+ "Null type safety (type annotations): The expression of type \'@NonNull A<T2>\' needs unchecked conversion to conform to \'@NonNull A<@NonNull T2>\'\n" +
"----------\n" +
"13. ERROR in nonnull\\WildcardNonNullTest.java (at line 81)\n" +
" g(new A<T2>());\n" +
@@ -11998,7 +12019,7 @@
"15. ERROR in nonnull\\WildcardNonNullTest.java (at line 87)\n" +
" g(new A<@Nullable T2>());\n" +
" ^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'@NonNull A<@NonNull T2>\' but this expression has type \'A<@Nullable T2>\'\n" +
+ "Null type mismatch (type annotations): required \'@NonNull A<@NonNull T2>\' but this expression has type \'@NonNull A<@Nullable T2>\'\n" +
"----------\n" +
"16. ERROR in nonnull\\WildcardNonNullTest.java (at line 87)\n" +
" g(new A<@Nullable T2>());\n" +
@@ -12162,7 +12183,7 @@
"12. WARNING in nullable\\WildcardNullableTest.java (at line 81)\n" +
" g(new A<T2>());\n" +
" ^^^^^^^^^^^\n" +
- "Null type safety (type annotations): The expression of type \'A<T2>\' needs unchecked conversion to conform to \'@NonNull A<@Nullable T2>\'\n" +
+ "Null type safety (type annotations): The expression of type \'@NonNull A<T2>\' needs unchecked conversion to conform to \'@NonNull A<@Nullable T2>\'\n" +
"----------\n" +
"13. ERROR in nullable\\WildcardNullableTest.java (at line 81)\n" +
" g(new A<T2>());\n" +
@@ -12177,7 +12198,7 @@
"15. ERROR in nullable\\WildcardNullableTest.java (at line 84)\n" +
" g(new A<@NonNull T2>());\n" +
" ^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'@NonNull A<@Nullable T2>\' but this expression has type \'A<@NonNull T2>\'\n" +
+ "Null type mismatch (type annotations): required \'@NonNull A<@Nullable T2>\' but this expression has type \'@NonNull A<@NonNull T2>\'\n" +
"----------\n" +
"16. ERROR in nullable\\WildcardNullableTest.java (at line 84)\n" +
" g(new A<@NonNull T2>());\n" +
@@ -13400,6 +13421,8 @@
);
}
public void testBug484926locals() {
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.IGNORE);
runNegativeTestWithLibs(
new String[] {
"test/NNBDOnLocalOrField.java",
@@ -13432,12 +13455,12 @@
" }\n" +
"}\n"
},
- getCompilerOptions(),
+ options,
"----------\n" +
"1. ERROR in test\\NNBDOnLocalOrField.java (at line 16)\n" +
" AtomicReference<String> x2 = new AtomicReference<@NonNull String>(), x3=new AtomicReference<@Nullable String>();\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'AtomicReference<@NonNull String>\' but this expression has type \'AtomicReference<@Nullable String>\'\n" +
+ "Null type mismatch (type annotations): required \'AtomicReference<@NonNull String>\' but this expression has type \'@NonNull AtomicReference<@Nullable String>\'\n" +
"----------\n" +
"2. ERROR in test\\NNBDOnLocalOrField.java (at line 21)\n" +
" x1.set(null);\n" +
@@ -13457,6 +13480,8 @@
);
}
public void testBug484926fields() {
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.IGNORE);
runNegativeTestWithLibs(
new String[] {
"test/NNBDOnLocalOrField.java",
@@ -13489,12 +13514,12 @@
" }\n" +
"}\n"
},
- getCompilerOptions(),
+ options,
"----------\n" +
"1. ERROR in test\\NNBDOnLocalOrField.java (at line 15)\n" +
" AtomicReference<String> x2 = new AtomicReference<@NonNull String>(), x3=new AtomicReference<@Nullable String>();\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type mismatch (type annotations): required \'@NonNull AtomicReference<@NonNull String>\' but this expression has type \'AtomicReference<@Nullable String>\'\n" +
+ "Null type mismatch (type annotations): required \'@NonNull AtomicReference<@NonNull String>\' but this expression has type \'@NonNull AtomicReference<@Nullable String>\'\n" +
"----------\n" +
"2. ERROR in test\\NNBDOnLocalOrField.java (at line 21)\n" +
" x1.set(null);\n" +
@@ -17840,4 +17865,147 @@
"Potential null pointer access: The method get() may return null\n" +
"----------\n");
}
+public void testBug482242_simple() {
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.ERROR);
+ runNegativeTestWithLibs(
+ new String[] {
+ "Test.java",
+ "import java.util.*;\n" +
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class Test {\n" +
+ " static void dangerous(List<String> list) {\n" +
+ " list.add(null);\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " List<@NonNull String> l = new ArrayList<>();\n" +
+ " dangerous(l);\n" +
+ " for (String string : l)\n" +
+ " System.out.println(string.toLowerCase());\n" +
+ " }\n" +
+ "}\n"
+ },
+ options,
+ "----------\n" +
+ "1. ERROR in Test.java (at line 9)\n" +
+ " dangerous(l);\n" +
+ " ^\n" +
+ "Unsafe null type conversion (type annotations): The value of type \'List<@NonNull String>\' is made accessible using the less-annotated type \'List<String>\'\n" +
+ "----------\n");
+}
+public void testBug482242_intermediate() {
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.ERROR);
+ runNegativeTestWithLibs(
+ new String[] {
+ "Test.java",
+ "import java.util.*;\n" +
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " ArrayList<@NonNull String> list = new ArrayList<>();\n" +
+ " collect(list, null);\n" +
+ " for (String s : list)\n" +
+ " System.out.println(s.toUpperCase());\n" +
+ " }\n" +
+ " static void collect(List<@NonNull String> list, String string) {\n" +
+ " list.add(string); // (1)\n" +
+ " insert(list, string); // (2)\n" +
+ " }\n" +
+ " static void insert(List<? super String> l, String s) {\n" +
+ " l.add(s);\n" +
+ " }\n" +
+ "}\n"
+ },
+ options,
+ "----------\n" +
+ "1. WARNING in Test.java (at line 12)\n" +
+ " list.add(string); // (1)\n" +
+ " ^^^^^^\n" +
+ "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'@NonNull String\'\n" +
+ "----------\n" +
+ "2. ERROR in Test.java (at line 13)\n" +
+ " insert(list, string); // (2)\n" +
+ " ^^^^\n" +
+ "Unsafe null type conversion (type annotations): The value of type \'List<@NonNull String>\' is made accessible using the less-annotated type \'List<? super String>\'\n" +
+ "----------\n");
+}
+public void testBug482242_annotatedTypeVariable() {
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.ERROR);
+ runNegativeTestWithLibs(
+ new String[] {
+ "Test.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "\n" +
+ "interface List<T extends @NonNull Object> {\n" +
+ " void add(T elem);" +
+ "}\n" +
+ "public class Test {\n" +
+ " public static void test(List<@NonNull String> list) {\n" +
+ " collect(list, null);\n" +
+ " }\n" +
+ " static void collect(List<@NonNull String> list, String string) {\n" +
+ " insert(list, string);\n" +
+ " }\n" +
+ " static void insert(List<? super String> l, String s) {\n" + // type error at declaration site, no need to signal at the call site
+ " l.add(s);\n" +
+ " }\n" +
+ "}\n"
+ },
+ options,
+ "----------\n" +
+ "1. ERROR in Test.java (at line 12)\n" +
+ " static void insert(List<? super String> l, String s) {\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "Null constraint mismatch: The type \'? super String\' is not a valid substitute for the type parameter \'T extends @NonNull Object\'\n" +
+ "----------\n" +
+ "2. WARNING in Test.java (at line 13)\n" +
+ " l.add(s);\n" +
+ " ^\n" +
+ "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'capture#of ? super String\'\n" +
+ "----------\n");
+}
+public void testBug482242_boundedWildcard() {
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.ERROR);
+ runNegativeTestWithLibs(
+ new String[] {
+ "Test.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "\n" +
+ "interface List<T extends @NonNull Object> {\n" +
+ " void add(T elem);" +
+ "}\n" +
+ "public class Test {\n" +
+ " public static void test(List<@NonNull String> list) {\n" +
+ " collect(list, null);\n" +
+ " }\n" +
+ " static void collect(List<@NonNull String> list, String string) {\n" +
+ " insert(list, string);\n" +
+ " }\n" +
+ " static void insert(List<? super @Nullable String> l, String s) {\n" +
+ " l.add(s);\n" +
+ " }\n" +
+ "}\n"
+ },
+ options,
+ "----------\n" +
+ "1. ERROR in Test.java (at line 10)\n" +
+ " insert(list, string);\n" +
+ " ^^^^\n" +
+ "Null type mismatch (type annotations): required \'List<? super @Nullable String>\' but this expression has type \'List<@NonNull String>\'\n" +
+ "----------\n" +
+ "2. ERROR in Test.java (at line 12)\n" +
+ " static void insert(List<? super @Nullable String> l, String s) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Null constraint mismatch: The type \'? super @Nullable String\' is not a valid substitute for the type parameter \'T extends @NonNull Object\'\n" +
+ "----------\n" +
+ "3. WARNING in Test.java (at line 13)\n" +
+ " l.add(s);\n" +
+ " ^\n" +
+ "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'capture#of ? super @Nullable String\'\n" +
+ "----------\n");
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java
index a0b7fb6..9222fb7 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java
@@ -5848,7 +5848,7 @@
"1. ERROR in Try17.java (at line 7)\n" +
" System.out.println(FileSystems.getFileSystem(uri));\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Potential resource leak: \'<unassigned Closeable value from line 7>\' may not be closed\n" +
+ "Potential resource leak: \'<unassigned Closeable value>\' may not be closed\n" +
"----------\n",
options);
}
@@ -6399,4 +6399,42 @@
new String[] { "Y.java", ySource },
"", "", "", null);
}
+public void testBug559119() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses @Override
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR);
+ options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING);
+ runLeakWarningTest(
+ new String[] {
+ "Sequencer.java",
+ "interface Sequencer extends AutoCloseable {\n" +
+ " void close(); // no exception\n" +
+ "}\n",
+ "SequencerControl.java",
+ "public abstract class SequencerControl {\n" +
+ " public abstract Sequencer getSequencer();\n" +
+ " @Override\n" +
+ " public boolean equals(Object obj) {\n" +
+ " if (obj != null) {\n" +
+ " if (getClass().equals(obj.getClass())) {\n" +
+ " return ((SequencerControl)obj).getSequencer().equals(getSequencer());\n" +
+ " }\n" +
+ " }\n" +
+ " return false;\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. WARNING in SequencerControl.java (at line 7)\n" +
+ " return ((SequencerControl)obj).getSequencer().equals(getSequencer());\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Potential resource leak: \'<unassigned Closeable value>\' may not be closed\n" +
+ "----------\n" +
+ "2. WARNING in SequencerControl.java (at line 7)\n" +
+ " return ((SequencerControl)obj).getSequencer().equals(getSequencer());\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "Potential resource leak: \'<unassigned Closeable value>\' may not be closed\n" +
+ "----------\n",
+ options);
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java
index 3f8bd30..e8c64cc 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java
@@ -1540,5 +1540,19 @@
assertTrue(false);
}
}
-
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=422760
+ */
+ public void testBug422760() {
+ String sourceA001 = "\\u0660";
+ IScanner scanner = ToolFactory.createScanner(false, true, false, false);
+ scanner.setSource(sourceA001.toCharArray());
+ int token = 0;
+ try {
+ token = scanner.getNextToken();
+ } catch (InvalidInputException e) {
+ assertTrue(false);
+ }
+ assertEquals("Wrong token type", ITerminalSymbols.TokenNameIntegerLiteral, token);
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
index 26bab5a..3bbf65b 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
@@ -13085,4 +13085,25 @@
" }\n" +
"}");
}
+/**
+ * https://bugs.eclipse.org/559006 - [formatter] Wrong indentation in region after wrapped line
+ */
+public void testBug559006() {
+ this.formatterPrefs.page_width = 50;
+ formatSource(
+ "class C {\n" +
+ " void f() {\n" +
+ " doSomething(aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbb,\n" +
+ " + ccccccccccccccccccc);\n" +
+ "[# doSomethingElse();#]\n" +
+ " }\n" +
+ "}",
+ "class C {\n" +
+ " void f() {\n" +
+ " doSomething(aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbb,\n" +
+ " + ccccccccccccccccccc);\n" +
+ " doSomethingElse();\n" +
+ " }\n" +
+ "}");
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
index 4a92277..01641b6 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -24638,10 +24638,10 @@
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
assertResults(
- "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.TXYU<TT;>;, (Ljava.lang.String;Ljava.lang.String;)V, TXYU, (s, s2), " + (R_DEFAULT + 25) + "}\n" +
- " TXYU[TYPE_REF]{TXYU, test, Ltest.TXYU;, null, null, " + (R_DEFAULT + 25) + "}\n" +
- "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.TXYU<TT;>;, (TT;)V, TXYU, (t), " + (R_DEFAULT + 25) + "}\n" +
- " TXYU[TYPE_REF]{TXYU, test, Ltest.TXYU;, null, null, " + (R_DEFAULT + 25) + "}",
+ "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.TXYU<TT;>;, (Ljava.lang.String;Ljava.lang.String;)V, TXYU, (s, s2), " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}\n" +
+ " TXYU[TYPE_REF]{TXYU, test, Ltest.TXYU;, null, null, " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}\n" +
+ "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.TXYU<TT;>;, (TT;)V, TXYU, (t), " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}\n" +
+ " TXYU[TYPE_REF]{TXYU, test, Ltest.TXYU;, null, null, " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}",
requestor.getResults());
assertEquals(true,
requestor.canUseDiamond(0));
@@ -24681,10 +24681,10 @@
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
assertResults(
- "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.TXYU<TT;>;, (Ljava.lang.String;Ljava.lang.String;)V, TXYU, (s, s2), " + (R_DEFAULT + 25) + "}\n" +
- " TXYU[TYPE_REF]{TXYU, test, Ltest.TXYU;, null, null, " + (R_DEFAULT + 25) + "}\n" +
- "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.TXYU<TT;>;, (TT;)V, TXYU, (t), " + (R_DEFAULT + 25) + "}\n" +
- " TXYU[TYPE_REF]{TXYU, test, Ltest.TXYU;, null, null, " + (R_DEFAULT + 25) + "}",
+ "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.TXYU<TT;>;, (Ljava.lang.String;Ljava.lang.String;)V, TXYU, (s, s2), " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}\n" +
+ " TXYU[TYPE_REF]{TXYU, test, Ltest.TXYU;, null, null, " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}\n" +
+ "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.TXYU<TT;>;, (TT;)V, TXYU, (t), " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}\n" +
+ " TXYU[TYPE_REF]{TXYU, test, Ltest.TXYU;, null, null, " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}",
requestor.getResults());
assertEquals(false,
requestor.canUseDiamond(1));
@@ -24727,10 +24727,10 @@
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
assertResults(
- "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.Test<Ljava.lang.Object;>.TXYU;, (Ljava.lang.String;Ljava.lang.String;)V, TXYU, (s, s2), " + (R_DEFAULT + 25) + "}\n" +
- " Test.TXYU[TYPE_REF]{TXYU, test, Ltest.Test$TXYU;, null, null, " + (R_DEFAULT + 25) + "}\n" +
- "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.Test<Ljava.lang.Object;>.TXYU;, (TT;)V, TXYU, (t), " + (R_DEFAULT + 25) + "}\n" +
- " Test.TXYU[TYPE_REF]{TXYU, test, Ltest.Test$TXYU;, null, null, " + (R_DEFAULT + 25) + "}",
+ "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.Test<Ljava.lang.Object;>.TXYU;, (Ljava.lang.String;Ljava.lang.String;)V, TXYU, (s, s2), " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}\n" +
+ " Test.TXYU[TYPE_REF]{TXYU, test, Ltest.Test$TXYU;, null, null, " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}\n" +
+ "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.Test<Ljava.lang.Object;>.TXYU;, (TT;)V, TXYU, (t), " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}\n" +
+ " Test.TXYU[TYPE_REF]{TXYU, test, Ltest.Test$TXYU;, null, null, " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}",
requestor.getResults());
assertEquals(true,
requestor.canUseDiamond(0));
@@ -24773,10 +24773,10 @@
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
assertResults(
- "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.Test<Ljava.lang.Object;>.TXYU;, (Ljava.lang.String;Ljava.lang.String;)V, TXYU, (s, s2), " + (R_DEFAULT + 25) + "}\n" +
- " Test.TXYU[TYPE_REF]{TXYU, test, Ltest.Test$TXYU;, null, null, " + (R_DEFAULT + 25) + "}\n" +
- "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.Test<Ljava.lang.Object;>.TXYU;, (TT;)V, TXYU, (t), " + (R_DEFAULT + 25) + "}\n" +
- " Test.TXYU[TYPE_REF]{TXYU, test, Ltest.Test$TXYU;, null, null, " + (R_DEFAULT + 25) + "}",
+ "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.Test<Ljava.lang.Object;>.TXYU;, (Ljava.lang.String;Ljava.lang.String;)V, TXYU, (s, s2), " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}\n" +
+ " Test.TXYU[TYPE_REF]{TXYU, test, Ltest.Test$TXYU;, null, null, " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}\n" +
+ "TXYU[CONSTRUCTOR_INVOCATION]{(), Ltest.Test<Ljava.lang.Object;>.TXYU;, (TT;)V, TXYU, (t), " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}\n" +
+ " Test.TXYU[TYPE_REF]{TXYU, test, Ltest.Test$TXYU;, null, null, " + (R_DEFAULT + R_EXACT_EXPECTED_TYPE + 25) + "}",
requestor.getResults());
assertEquals(false,
requestor.canUseDiamond(1));
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java
index 4eb839d..0b8b1c0 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2018 IBM Corporation and others.
+ * Copyright (c) 2014, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -19,6 +19,8 @@
import junit.framework.Test;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.CompletionProposal;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
@@ -3704,4 +3706,37 @@
"applyToEitherAsync[METHOD_REF]{applyToEitherAsync(), Ljava.util.concurrent.CompletableFuture<Ljava.lang.Double;>;, <U:Ljava.lang.Object;>(Ljava.util.concurrent.CompletionStage<+Ljava.lang.Double;>;Ljava.util.function.Function<-Ljava.lang.Double;TU;>;Ljava.util.concurrent.Executor;)Ljava.util.concurrent.CompletableFuture<TU;>;, applyToEitherAsync, (arg0, arg1, arg2), " + relevance2 + "}",
requestor.getResults());
}
+/**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=277691
+ */
+public void testCompletionConstructorRelevance() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Foo.java",
+ "import java.util.Queue;\n" +
+ "\n" +
+ "public class Foo {\n" +
+ " public void foo () {\n" +
+ " Queue<String> res = new LinkedBlockingQueue<>();\n" +
+ " }\n" +
+ "}");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.setAllowsRequiredProposals(CompletionProposal.CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true);
+
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "new LinkedBlocking";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, new NullProgressMonitor());
+
+ int expectedConstructorRelevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED + R_CASE + R_EXPECTED_TYPE + R_CONSTRUCTOR;
+ assertResults(
+ "LinkedBlockingDeque[CONSTRUCTOR_INVOCATION]{(), Ljava.util.concurrent.LinkedBlockingDeque;, ()V, LinkedBlockingDeque, null, " + expectedConstructorRelevance + "}\n" +
+ "LinkedBlockingDeque[CONSTRUCTOR_INVOCATION]{(), Ljava.util.concurrent.LinkedBlockingDeque;, (I)V, LinkedBlockingDeque, (arg0), " + expectedConstructorRelevance + "}\n" +
+ "LinkedBlockingDeque[CONSTRUCTOR_INVOCATION]{(), Ljava.util.concurrent.LinkedBlockingDeque;, (Ljava.util.Collection<+TE;>;)V, LinkedBlockingDeque, (arg0), " + expectedConstructorRelevance + "}\n" +
+ "LinkedBlockingQueue[CONSTRUCTOR_INVOCATION]{(), Ljava.util.concurrent.LinkedBlockingQueue;, ()V, LinkedBlockingQueue, null, " + expectedConstructorRelevance + "}\n" +
+ "LinkedBlockingQueue[CONSTRUCTOR_INVOCATION]{(), Ljava.util.concurrent.LinkedBlockingQueue;, (I)V, LinkedBlockingQueue, (arg0), " + expectedConstructorRelevance + "}\n" +
+ "LinkedBlockingQueue[CONSTRUCTOR_INVOCATION]{(), Ljava.util.concurrent.LinkedBlockingQueue;, (Ljava.util.Collection<+TE;>;)V, LinkedBlockingQueue, (arg0), " + expectedConstructorRelevance + "}",
+ requestor.getResults());
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java
index 6fb0f9b..18d695a 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7611,7 +7611,7 @@
result.proposals);
} else {
assertResults(
- "Test<ZT>[TYPE_REF]{Test, test0232, Ltest0232.Test<TZT;>;, null, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
+ "Test<ZT>[TYPE_REF]{Test, test0232, Ltest0232.Test<TZT;>;, null, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXPECTED_TYPE) + "}",
result.proposals);
}
}
@@ -13943,7 +13943,7 @@
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED;
+ int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
assertResults(
"expectedTypesSignatures={Ltest.X<Ljava.lang.String;>;}\n" +
@@ -13972,7 +13972,7 @@
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED;
+ int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
assertResults(
"expectedTypesSignatures={Ltest.X<Ljava.lang.String;>;}\n" +
@@ -14003,7 +14003,7 @@
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED;
+ int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
assertResults(
"expectedTypesSignatures={Ltest.X<Ljava.lang.String;>.X1<Ljava.lang.String;>;}\n" +
@@ -14036,7 +14036,7 @@
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED;
+ int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
assertResults(
"expectedTypesSignatures={Ltest.X<Ljava.lang.String;>.X1<Ljava.lang.Object;>.X11<Ljava.lang.String;>;}\n" +
@@ -14068,7 +14068,7 @@
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED;
+ int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
assertResults(
"expectedTypesSignatures={Ltest.X$X1<Ljava.lang.String;>;}\n" +
@@ -14098,7 +14098,7 @@
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED;
+ int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
assertResults(
"expectedTypesSignatures={Ltest.X<Ljava.lang.String;>;}\n" +
@@ -14129,7 +14129,7 @@
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED;
+ int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
assertResults(
"expectedTypesSignatures={Ltest.X<TT;>.X1<Ljava.lang.String;>;}\n" +
@@ -14160,7 +14160,7 @@
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED;
+ int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
assertResults(
"expectedTypesSignatures={Ltest.X$X1<Ljava.lang.String;>;}\n" +
@@ -14188,7 +14188,7 @@
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED;
+ int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
assertResults(
"expectedTypesSignatures={Ltest.X<Ljava.lang.String;>;}\n" +
@@ -14220,7 +14220,7 @@
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED;
+ int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
assertResults(
"expectedTypesSignatures={Ltest.X$X1<Ljava.lang.String;>;}\n" +
@@ -14250,7 +14250,7 @@
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED;
+ int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
assertResults(
"expectedTypesSignatures={Ltest.X<Ljava.lang.String;Ljava.lang.String;>;}\n" +
@@ -14285,7 +14285,7 @@
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED;
+ int relevance = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
assertResults(
"expectedTypesSignatures={Ltest.X1<Ljava.lang.String;>;}\n" +
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java
index b205d76..11e5b2e 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2017 GK Software AG, and others.
+ * Copyright (c) 2014, 2020 GK Software AG, and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -2359,7 +2359,7 @@
}
}
- @SuppressWarnings("deprecation")
+ @SuppressWarnings("deprecation")
public void testBug508955() throws CoreException, IOException {
myCreateJavaProject("TestLibs");
addLibraryWithExternalAnnotations(this.project, "lib1.jar", "annots",
@@ -2624,4 +2624,40 @@
CompilationUnit reconciled = cu.reconcile(getJSL9(), true, null, new NullProgressMonitor());
assertNoProblems(reconciled.getProblems());
}
+
+ @SuppressWarnings("deprecation")
+ public void testBug482242() throws CoreException, IOException {
+ try {
+ String projectName = "Bug482242";
+ setupJavaProject(projectName, true, true);
+ this .project.setOption(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.WARNING);
+ addEeaToVariableEntry("JCL18_FULL", "/"+projectName+"/annots");
+ IPackageFragment fragment = this.project.getPackageFragmentRoots()[0].createPackageFragment("test1", true, null);
+ ICompilationUnit unit = fragment.getCompilationUnit("Test.java").getWorkingCopy(new NullProgressMonitor());
+ CompilationUnit reconciled = unit.reconcile(AST.JLS8, true, null, new NullProgressMonitor());
+ IProblem[] problems = reconciled.getProblems();
+ assertProblems(problems,
+ new String[] {
+ "Pb(983) Unsafe null type conversion (type annotations): The value of type 'Collector<@NonNull String,capture#of ?,Set<@NonNull String>>' " +
+ "is made accessible using the less-annotated type 'Collector<? super String,Object,Set<@NonNull String>>'",
+ },
+ new int[] {11},
+ new int[] { ProblemSeverities.Warning });
+
+ this.project.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
+ IMarker[] markers = this.project.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
+ sortMarkers(markers);
+ assertMarkers("Markers after full build",
+ "Unsafe null type conversion (type annotations): The value of type 'Collector<@NonNull String,capture#of ?,Set<@NonNull String>>' is made accessible using the less-annotated type 'Collector<? super String,Object,Set<@NonNull String>>'",
+ markers);
+ int[] severities = new int[] { IMarker.SEVERITY_WARNING };
+ for (int i = 0; i < markers.length; i++) {
+ IMarker marker = markers[i];
+ assertEquals("severity of "+marker.getAttribute(IMarker.MESSAGE),
+ severities[i], marker.getAttribute(IMarker.SEVERITY));
+ }
+ } finally {
+ deleteProject("Bug500024");
+ }
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java
index 70db632..76776eb 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java
@@ -3267,4 +3267,62 @@
if (javaProject1 != null) deleteProject(javaProject1);
}
}
+public void testBug559210() throws CoreException {
+ try {
+ createJavaProject("P", new String[] {"src"}, new String[] {"JCL_LIB", "lib"}, "bin", "1.7");
+ createFolder("/P/src/java/io");
+ createFile(
+ "/P/src/java/io/Closeable.java",
+ "pakage java.io;\n" +
+ "public interface Closeable { void close(); }\n");
+ createFile(
+ "/P/src/java/io/InputStream.java",
+ "pakage java.io;\n" +
+ "public abstract class InputStream implements Closeable { }\n");
+
+ createFolder("/P/src/p");
+ createFile(
+ "/P/src/p/ReferenceInputStream.java",
+ "pakage p;\n" +
+ "public class ReferenceInputStream extends java.io.InputStream {\n" +
+ " private final File reference;\n" +
+ "\n" +
+ " public ReferenceInputStream(File reference) {\n" +
+ " this.reference = reference;\n" +
+ " }\n" +
+ "\n" +
+ " /* This method should not be called.\n" +
+ " */\n" +
+ " @Override\n" +
+ " public int read() throws IOException {\n" +
+ " throw new IOException();\n" +
+ " }\n" +
+ "\n" +
+ " public File getReference() {\n" +
+ " return reference;\n" +
+ " }\n" +
+ "}"
+ );
+ createFile(
+ "/P/src/p/Storage.java",
+ "pakage p;\n" +
+ "import p.ReferenceInputStream;\n" +
+ "public class Storage {\n" +
+ "\n" +
+ " public ReferenceInputStream stream;\n" +
+ "}"
+ );
+ getProject("P").build(IncrementalProjectBuilder.FULL_BUILD, null);
+ waitForAutoBuild();
+ ITypeHierarchy hierarchy = getCompilationUnit("/P/src/p/Storage.java").getTypes()[0].newSupertypeHierarchy(null);
+ assertHierarchyEquals(
+ "Focus: Storage [in Storage.java [in p [in src [in P]]]]\n" +
+ "Super types:\n" +
+ " Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
+ "Sub types:\n",
+ hierarchy);
+ } finally {
+ deleteProject("P");
+ }
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/nd/util/ResourceHelper.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/nd/util/ResourceHelper.java
index a017a00..1345e5a 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/nd/util/ResourceHelper.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/nd/util/ResourceHelper.java
@@ -498,10 +498,9 @@
*/
public static String getContents(IPath fullPath) throws IOException {
FileInputStream stream = new FileInputStream(fullPath.toFile());
- try {
+ try (Reader reader = new BufferedReader(new InputStreamReader(stream, Charset.defaultCharset()))){
// Avoid using java.nio.channels.FileChannel,
// see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4715154
- Reader reader = new BufferedReader(new InputStreamReader(stream, Charset.defaultCharset()));
StringBuilder builder = new StringBuilder();
char[] buffer = new char[8192];
int read;
@@ -509,8 +508,6 @@
builder.append(buffer, 0, read);
}
return builder.toString();
- } finally {
- stream.close();
}
}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/ExternalAnnotations18/Bug482242/.classpath b/org.eclipse.jdt.core.tests.model/workspace/ExternalAnnotations18/Bug482242/.classpath
new file mode 100644
index 0000000..3dfabed
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/ExternalAnnotations18/Bug482242/.classpath
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="var" path="JCL18_LIB">
+ <attributes>
+ <attribute name="annotationpath" value="annots"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.jdt.core.tests.model/workspace/ExternalAnnotations18/Bug482242/.project b/org.eclipse.jdt.core.tests.model/workspace/ExternalAnnotations18/Bug482242/.project
new file mode 100644
index 0000000..1cf4df7
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/ExternalAnnotations18/Bug482242/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Bug482242</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.jdt.core.tests.model/workspace/ExternalAnnotations18/Bug482242/annots/java/util/stream/Stream.eea b/org.eclipse.jdt.core.tests.model/workspace/ExternalAnnotations18/Bug482242/annots/java/util/stream/Stream.eea
new file mode 100644
index 0000000..d311f09
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/ExternalAnnotations18/Bug482242/annots/java/util/stream/Stream.eea
@@ -0,0 +1,4 @@
+class java/util/stream/Stream
+collect
+ <R:Ljava/lang/Object;A:Ljava/lang/Object;>(Ljava/util/stream/Collector<-TT;TA;TR;>;)TR;
+ <R:Ljava/lang/Object;A:Ljava/lang/Object;>(Ljava/util/stream/Collector<-TT;TA;TR;>;)T1R;
diff --git a/org.eclipse.jdt.core.tests.model/workspace/ExternalAnnotations18/Bug482242/src/test1/Test.java b/org.eclipse.jdt.core.tests.model/workspace/ExternalAnnotations18/Bug482242/src/test1/Test.java
new file mode 100644
index 0000000..8135abb
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/ExternalAnnotations18/Bug482242/src/test1/Test.java
@@ -0,0 +1,19 @@
+package test1;
+
+import java.util.Collections;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.eclipse.jdt.annotation.NonNull;
+
+public class Test {
+ static Set<@NonNull String> test1(Set<String> args) {
+ @NonNull Set<@NonNull String> mapped = args.stream().collect(Collectors.toSet());
+ return mapped;
+ }
+ public static void main(String[] args) {
+ Set<String> set = Collections.singleton(null);
+ for (@NonNull String s : test1(set))
+ System.out.println(s.toUpperCase());
+ }
+}
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
index 9fab44d..f8884c6 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -4816,7 +4816,7 @@
}
for (int i = 0; i <= this.expectedTypesPtr; i++) {
if((this.expectedTypesFilter & SUBTYPE) != 0
- && proposalType.isCompatibleWith(this.expectedTypes[i])) {
+ && (proposalType.erasure().isCompatibleWith(this.expectedTypes[i].erasure()))) {
if(CharOperation.equals(this.expectedTypes[i].qualifiedPackageName(), proposalType.qualifiedPackageName()) &&
CharOperation.equals(this.expectedTypes[i].qualifiedSourceName(), proposalType.qualifiedSourceName())) {
@@ -14114,12 +14114,14 @@
typeCompletion = simpleTypeName;
}
+ ReferenceBinding typeBinding = this.lookupEnvironment.getType(CharOperation.splitOn('.', fullyQualifiedName));
+
int relevance = computeBaseRelevance();
relevance += computeRelevanceForResolution();
relevance += computeRelevanceForInterestingProposal();
relevance += computeRelevanceForRestrictions(accessibility);
relevance += computeRelevanceForCaseMatching(this.completionToken, simpleTypeName);
- relevance += computeRelevanceForExpectingType(packageName, simpleTypeName);
+ relevance += computeRelevanceForExpectingType(typeBinding);
relevance += computeRelevanceForQualification(isQualified);
relevance += computeRelevanceForConstructor();
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
index 1a4d44d..2c0dc55 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
@@ -1905,6 +1905,10 @@
int NonNullMethodTypeVariableFromLegacyMethod = TypeRelated + 981;
/** @since 3.21 */
int MissingNullAnnotationImplicitlyUsed = Internal + 982;
+ /** @since 3.21 */
+ int AnnotatedTypeArgumentToUnannotated = Internal + 983;
+ /** @since 3.21 */
+ int AnnotatedTypeArgumentToUnannotatedSuperHint = Internal + 984;
// Java 8 work
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java
index 32dfb67..c2e89fd 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -6130,7 +6130,7 @@
private boolean isLikelyLocalTypeName(char[] typeName) {
int dollarPos = CharOperation.lastIndexOf('$', typeName);
- while (dollarPos != -1) {
+ while (dollarPos != -1 && dollarPos+1 < typeName.length) {
if (Character.isDigit(typeName[dollarPos+1]))
return true; // name segment starts with a digit => likely a local type (but still "$0" etc. could be part of the source name)
dollarPos = CharOperation.lastIndexOf('$', typeName, 0, dollarPos-1);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java
index dcf3a2a..caf794b 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -642,12 +642,13 @@
}
if (compilerOptions.isAnnotationBasedNullAnalysisEnabled) {
ImplicitNullAnnotationVerifier.ensureNullnessIsKnown(this.binding, scope);
- if (compilerOptions.sourceLevel >= ClassFileConstants.JDK1_8) {
+ if (scope.environment().usesNullTypeAnnotations()) {
if (this.binding instanceof ParameterizedGenericMethodBinding && this.typeArguments != null) {
TypeVariableBinding[] typeVariables = this.binding.original().typeVariables();
for (int i = 0; i < this.typeArguments.length; i++)
this.typeArguments[i].checkNullConstraints(scope, (ParameterizedGenericMethodBinding) this.binding, typeVariables, i);
}
+ this.resolvedType = scope.environment().createAnnotatedType(this.resolvedType, new AnnotationBinding[] {scope.environment().getNonNullAnnotation()});
}
}
if (compilerOptions.sourceLevel >= ClassFileConstants.JDK1_8 &&
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Block.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Block.java
index 0091d4c..7f34063 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Block.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Block.java
@@ -25,6 +25,7 @@
import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.codegen.*;
import org.eclipse.jdt.internal.compiler.flow.*;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.lookup.*;
import org.eclipse.objectteams.otdt.internal.core.compiler.control.Config;
import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.InsertTypeAdjustmentsVisitor;
@@ -53,7 +54,8 @@
// empty block
if (this.statements == null) return flowInfo;
int complaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED;
- boolean enableSyntacticNullAnalysisForFields = currentScope.compilerOptions().enableSyntacticNullAnalysisForFields;
+ CompilerOptions compilerOptions = currentScope.compilerOptions();
+ boolean enableSyntacticNullAnalysisForFields = compilerOptions.enableSyntacticNullAnalysisForFields;
for (int i = 0, max = this.statements.length; i < max; i++) {
Statement stat = this.statements[i];
if ((complaintLevel = stat.complainIfUnreachable(flowInfo, this.scope, complaintLevel, true)) < Statement.COMPLAINED_UNREACHABLE) {
@@ -64,6 +66,9 @@
if (enableSyntacticNullAnalysisForFields) {
flowContext.expireNullCheckedFieldInfo();
}
+ if (compilerOptions.analyseResourceLeaks) {
+ FakedTrackingVariable.cleanUpUnassigned(this.scope, stat, flowInfo);
+ }
}
if (this.scope != currentScope) {
// if block is tracking any resources other than the enclosing 'currentScope', analyse them now:
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
index 729123a..3758e44 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -41,6 +41,7 @@
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.codegen.*;
import org.eclipse.jdt.internal.compiler.flow.*;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.lookup.*;
import org.eclipse.jdt.internal.compiler.parser.*;
import org.eclipse.jdt.internal.compiler.problem.*;
@@ -299,7 +300,8 @@
// propagate to statements
if (this.statements != null) {
- boolean enableSyntacticNullAnalysisForFields = this.scope.compilerOptions().enableSyntacticNullAnalysisForFields;
+ CompilerOptions compilerOptions = this.scope.compilerOptions();
+ boolean enableSyntacticNullAnalysisForFields = compilerOptions.enableSyntacticNullAnalysisForFields;
int complaintLevel = (nonStaticFieldInfoReachMode & FlowInfo.UNREACHABLE) == 0 ? Statement.NOT_COMPLAINED : Statement.COMPLAINED_FAKE_REACHABLE;
for (int i = 0, count = this.statements.length; i < count; i++) {
Statement stat = this.statements[i];
@@ -309,6 +311,9 @@
if (enableSyntacticNullAnalysisForFields) {
constructorContext.expireNullCheckedFieldInfo();
}
+ if (compilerOptions.analyseResourceLeaks) {
+ FakedTrackingVariable.cleanUpUnassigned(this.scope, stat, flowInfo);
+ }
}
}
// check for missing returning path
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java
index 317677f..9e2e823 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2019 GK Software AG and others.
+ * Copyright (c) 2011, 2020 GK Software AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -24,6 +24,7 @@
import java.util.Set;
import org.eclipse.jdt.core.compiler.CharOperation;
+import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
import org.eclipse.jdt.internal.compiler.flow.FinallyFlowContext;
@@ -740,6 +741,28 @@
}
}
+ /** Unassigned closeables are not visible beyond their enclosing statement, immediately report & remove after each statement. */
+ public static void cleanUpUnassigned(BlockScope scope, ASTNode location, FlowInfo flowInfo) {
+ if (!scope.hasResourceTrackers()) return;
+ location.traverse(new ASTVisitor() {
+ @Override
+ public boolean visit(MessageSend messageSend, BlockScope skope) {
+ FakedTrackingVariable closeTracker = messageSend.closeTracker;
+ if (closeTracker != null) {
+ if (closeTracker.originalBinding == null) {
+ int nullStatus = flowInfo.nullStatus(closeTracker.binding);
+ if ((nullStatus & (FlowInfo.POTENTIALLY_NULL | FlowInfo.NULL)) != 0) {
+ closeTracker.reportError(skope.problemReporter(), messageSend, nullStatus);
+ }
+ closeTracker.withdraw();
+ }
+ }
+ return true;
+ }
+ },
+ scope);
+ }
+
/** Answer wither the given type binding is a subtype of java.lang.AutoCloseable. */
public static boolean isAnyCloseable(TypeBinding typeBinding) {
return typeBinding instanceof ReferenceBinding
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
index acda83d..c0a39da 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -169,7 +169,8 @@
}
// propagate to statements
if (this.statements != null) {
- boolean enableSyntacticNullAnalysisForFields = this.scope.compilerOptions().enableSyntacticNullAnalysisForFields;
+ CompilerOptions compilerOptions = this.scope.compilerOptions();
+ boolean enableSyntacticNullAnalysisForFields = compilerOptions.enableSyntacticNullAnalysisForFields;
int complaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) == 0 ? Statement.NOT_COMPLAINED : Statement.COMPLAINED_FAKE_REACHABLE;
for (int i = 0, count = this.statements.length; i < count; i++) {
Statement stat = this.statements[i];
@@ -179,6 +180,9 @@
if (enableSyntacticNullAnalysisForFields) {
methodContext.expireNullCheckedFieldInfo();
}
+ if (compilerOptions.analyseResourceLeaks) {
+ FakedTrackingVariable.cleanUpUnassigned(this.scope, stat, flowInfo);
+ }
}
} else {
// method with empty body should not be flagged as static.
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/NullAnnotationMatching.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/NullAnnotationMatching.java
index bf66588..2be11ef 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/NullAnnotationMatching.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/NullAnnotationMatching.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2019 GK Software AG and others.
+ * Copyright (c) 2013, 2020 GK Software AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -101,6 +101,8 @@
LEGACY_WARNING,
/** Need unchecked conversion from unannotated to annotated. */
UNCHECKED,
+ /** Need unchecked conversion to pass type with annotated type arguments into unannotated code. */
+ UNCHECKED_TO_UNANNOTATED,
/** Definite nullity mismatch. */
MISMATCH;
@@ -127,10 +129,11 @@
this.nullStatus = nullStatus;
}
- public boolean isAnyMismatch() { return this.severity.isAnyMismatch(); }
- public boolean isUnchecked() { return this.severity == Severity.UNCHECKED; }
- public boolean isDefiniteMismatch() { return this.severity == Severity.MISMATCH; }
- public boolean wantToReport() { return this.severity == Severity.LEGACY_WARNING; }
+ public boolean isAnyMismatch() { return this.severity.isAnyMismatch(); }
+ public boolean isUnchecked() { return this.severity == Severity.UNCHECKED || this.severity == Severity.UNCHECKED_TO_UNANNOTATED; }
+ public boolean isAnnotatedToUnannotated() { return this.severity == Severity.UNCHECKED_TO_UNANNOTATED; }
+ public boolean isDefiniteMismatch() { return this.severity == Severity.MISMATCH; }
+ public boolean wantToReport() { return this.severity == Severity.LEGACY_WARNING; }
public boolean isPotentiallyNullMismatch() {
return !isDefiniteMismatch() && this.nullStatus != -1 && (this.nullStatus & FlowInfo.POTENTIALLY_NULL) != 0;
@@ -228,6 +231,7 @@
try {
Severity severity = Severity.OK;
TypeBinding superTypeHint = null;
+ TypeBinding originalRequiredType = requiredType;
NullAnnotationMatching okStatus = NullAnnotationMatching.NULL_ANNOTATIONS_OK;
if (areSameTypes(requiredType, providedType, providedSubstitute)) {
if ((requiredType.tagBits & TagBits.AnnotationNonNull) != 0)
@@ -288,7 +292,7 @@
} else {
if (i > 0)
currentNullStatus = -1; // don't use beyond the outermost dimension
- Severity dimSeverity = computeNullProblemSeverity(requiredBits, providedBits, currentNullStatus, i == 0 ? mode : mode.toDetail(), false);
+ Severity dimSeverity = computeNullProblemSeverity(requiredBits, providedBits, currentNullStatus, i == 0 ? mode : mode.toDetail(), null);
if (i > 0 && dimSeverity == Severity.UNCHECKED
&& providedExpression instanceof ArrayAllocationExpression
&& providedBits == 0 && requiredBits != 0)
@@ -322,11 +326,14 @@
// at toplevel (having a nullStatus) nullable matches all
} else {
long providedBits = providedNullTagBits(providedType);
- Severity s = computeNullProblemSeverity(requiredBits, providedBits, nullStatus, mode, requiredType.isTypeVariable());
+ Severity s = computeNullProblemSeverity(requiredBits, providedBits, nullStatus, mode, originalRequiredType);
if (s.isAnyMismatch() && requiredType.isWildcard() && requiredBits != 0) {
if (((WildcardBinding) requiredType).determineNullBitsFromDeclaration(null, null) == 0) {
- // wildcard has its nullBits from the type variable: avoid redundant warning.
- s = Severity.OK;
+ TypeVariableBinding typeVariable = ((WildcardBinding) requiredType).typeVariable();
+ if ((typeVariable.tagBits & TagBits.AnnotationNullMASK) != 0) {
+ // wildcard has its nullBits from the type variable
+ s = Severity.OK; // is already reported as illegal substitution
+ }
}
}
severity = severity.max(s);
@@ -433,6 +440,19 @@
return validNullTagBits(tagBits);
if (type.isWildcard()) {
+ WildcardBinding wildcardBinding = (WildcardBinding) type;
+ TypeBinding bound = wildcardBinding.bound;
+ tagBits = bound != null ? bound.tagBits & TagBits.AnnotationNullMASK : 0;
+ switch (wildcardBinding.boundKind) {
+ case Wildcard.SUPER:
+ if (tagBits == TagBits.AnnotationNullable)
+ return TagBits.AnnotationNullable; // type cannot require @NonNull
+ break;
+ case Wildcard.EXTENDS:
+ if (tagBits == TagBits.AnnotationNonNull)
+ return tagBits;
+ break;
+ }
return TagBits.AnnotationNullMASK;
}
@@ -544,29 +564,44 @@
* @param providedBits null tagBits of the provided type
* @param nullStatus -1 means: don't use, other values see constants in FlowInfo
* @param mode check mode (see {@link CheckMode})
- * @param requiredIsTypeVariable is the required type a type variable (possibly: "free type variable")?
+ * @param requiredType the required type, used, e.g., to check if it is a type variable (possibly: "free type variable")?
* @return see {@link #severity} for interpretation of values
*/
- private static Severity computeNullProblemSeverity(long requiredBits, long providedBits, int nullStatus, CheckMode mode, boolean requiredIsTypeVariable) {
+ private static Severity computeNullProblemSeverity(long requiredBits, long providedBits, int nullStatus, CheckMode mode, TypeBinding requiredType) {
if (requiredBits == providedBits)
return Severity.OK;
if (requiredBits == 0) {
switch (mode) {
+ case EXACT:
+ if (providedBits == TagBits.AnnotationNonNull && !(requiredType instanceof TypeVariableBinding))
+ return Severity.UNCHECKED_TO_UNANNOTATED;
+ return Severity.OK;
case COMPATIBLE:
case BOUND_CHECK:
case BOUND_SUPER_CHECK:
- case EXACT:
return Severity.OK;
case OVERRIDE_RETURN:
if (providedBits == TagBits.AnnotationNonNull)
return Severity.OK; // covariant redefinition to nonnull is good
- if (!requiredIsTypeVariable)
+ if (!(requiredType instanceof TypeVariableBinding))
return Severity.OK; // refining an unconstrained non-TVB return to nullable is also legal
return Severity.UNCHECKED;
case OVERRIDE:
return Severity.UNCHECKED; // warn about dropped annotation
}
} else if (requiredBits == TagBits.AnnotationNullMASK) {
+ if (mode == CheckMode.EXACT && providedBits == TagBits.AnnotationNonNull) {
+ if (requiredType instanceof WildcardBinding) {
+ WildcardBinding wildcard = (WildcardBinding) requiredType;
+ // passing '@NonNull X' into '? super Y' risks pollution with null
+ if (wildcard.boundKind == Wildcard.SUPER && providedBits == TagBits.AnnotationNonNull) {
+ TypeBinding bound = wildcard.bound;
+ if (bound != null && (bound.tagBits & TagBits.AnnotationNullMASK) != 0)
+ return Severity.OK; // when the wildcard is annotated via its bound, there is not annotated->unannotated conversion
+ return Severity.UNCHECKED_TO_UNANNOTATED;
+ }
+ }
+ }
return Severity.OK; // OK since LHS accepts either
} else if (requiredBits == TagBits.AnnotationNonNull) {
switch (mode) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
index 8a4270f..bd6a8d9 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -53,6 +53,7 @@
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme;
import org.eclipse.jdt.internal.compiler.impl.Constant;
+import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
@@ -498,12 +499,15 @@
final CompilerOptions compilerOptions = scope.compilerOptions();
if (compilerOptions.isAnnotationBasedNullAnalysisEnabled) {
ImplicitNullAnnotationVerifier.ensureNullnessIsKnown(this.binding, scope);
- if (compilerOptions.sourceLevel >= ClassFileConstants.JDK1_8) {
+ if (scope.environment().usesNullTypeAnnotations()) {
if (this.binding instanceof ParameterizedGenericMethodBinding && this.typeArguments != null) {
TypeVariableBinding[] typeVariables = this.binding.original().typeVariables();
for (int i = 0; i < this.typeArguments.length; i++)
this.typeArguments[i].checkNullConstraints(scope, (ParameterizedGenericMethodBinding) this.binding, typeVariables, i);
}
+ if (this.resolvedType.isValidBinding()) {
+ this.resolvedType = scope.environment().createAnnotatedType(this.resolvedType, new AnnotationBinding[] {scope.environment().getNonNullAnnotation()});
+ }
}
}
if (compilerOptions.sourceLevel >= ClassFileConstants.JDK1_8 &&
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java
index beb8b61..a4f8fec 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java
@@ -113,6 +113,8 @@
// by returning the method passes the responsibility to the caller:
flowInfo = FakedTrackingVariable.markPassedToOutside(currentScope, this.expression, flowInfo, flowContext, true);
}
+ // don't wait till after this statement, because then flowInfo would be DEAD_END & thus cannot serve nullStatus any more:
+ FakedTrackingVariable.cleanUpUnassigned(currentScope, this.expression, flowInfo);
}
}
this.initStateIndex =
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ExternalAnnotationDecorator.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ExternalAnnotationDecorator.java
index 0846cf1..d67ce12 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ExternalAnnotationDecorator.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ExternalAnnotationDecorator.java
@@ -17,6 +17,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -225,7 +226,9 @@
} else {
ZipEntry entry = zipFile.getEntry(qualifiedBinaryFileName);
if (entry != null) {
- return new ExternalAnnotationProvider(zipFile.getInputStream(entry), qualifiedBinaryTypeName);
+ try(InputStream is = zipFile.getInputStream(entry)) {
+ return new ExternalAnnotationProvider(is, qualifiedBinaryTypeName);
+ }
}
}
return null;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java
index a9f41fb..e21856c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java
@@ -283,6 +283,7 @@
public static final String OPTION_ReportNonnullParameterAnnotationDropped = "org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped"; //$NON-NLS-1$
public static final String OPTION_PessimisticNullAnalysisForFreeTypeVariables = "org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables"; //$NON-NLS-1$
public static final String OPTION_ReportNonNullTypeVariableFromLegacyInvocation = "org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation"; //$NON-NLS-1$
+ public static final String OPTION_ReportAnnotatedTypeArgumentToUnannotated = "org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated"; //$NON-NLS-1$
public static final String OPTION_ReportUnlikelyCollectionMethodArgumentType = "org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType"; //$NON-NLS-1$
public static final String OPTION_ReportUnlikelyCollectionMethodArgumentTypeStrict = "org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict"; //$NON-NLS-1$
@@ -436,6 +437,7 @@
public static final int UnstableAutoModuleName = IrritantSet.GROUP2 | ASTNode.Bit26;
public static final int PreviewFeatureUsed = IrritantSet.GROUP2 | ASTNode.Bit27;
public static final int SuppressWarningsNotAnalysed = IrritantSet.GROUP2 | ASTNode.Bit28;
+ public static final int AnnotatedTypeArgumentToUnannotated = IrritantSet.GROUP2 | ASTNode.Bit29;
//{ObjectTeams: OT/J specific problems/irritants:
@@ -966,6 +968,8 @@
return OPTION_PessimisticNullAnalysisForFreeTypeVariables;
case NonNullTypeVariableFromLegacyInvocation:
return OPTION_ReportNonNullTypeVariableFromLegacyInvocation;
+ case AnnotatedTypeArgumentToUnannotated:
+ return OPTION_ReportAnnotatedTypeArgumentToUnannotated;
case UnlikelyCollectionMethodArgumentType:
return OPTION_ReportUnlikelyCollectionMethodArgumentType;
case UnlikelyEqualsArgumentType:
@@ -1239,6 +1243,7 @@
OPTION_ReportUnusedTypeParameter,
OPTION_InheritNullAnnotations,
OPTION_ReportNonnullParameterAnnotationDropped,
+ OPTION_ReportAnnotatedTypeArgumentToUnannotated,
OPTION_ReportUnlikelyCollectionMethodArgumentType,
OPTION_ReportUnlikelyEqualsArgumentType,
OPTION_ReportAPILeak,
@@ -1320,6 +1325,7 @@
case NonnullParameterAnnotationDropped:
case PessimisticNullAnalysisForFreeTypeVariables:
case NonNullTypeVariableFromLegacyInvocation:
+ case AnnotatedTypeArgumentToUnannotated:
return "null"; //$NON-NLS-1$
case FallthroughCase :
return "fallthrough"; //$NON-NLS-1$
@@ -1726,6 +1732,7 @@
optionsMap.put(OPTION_ReportUninternedIdentityComparison, this.complainOnUninternedIdentityComparison ? ENABLED : DISABLED);
optionsMap.put(OPTION_PessimisticNullAnalysisForFreeTypeVariables, getSeverityString(PessimisticNullAnalysisForFreeTypeVariables));
optionsMap.put(OPTION_ReportNonNullTypeVariableFromLegacyInvocation, getSeverityString(NonNullTypeVariableFromLegacyInvocation));
+ optionsMap.put(OPTION_ReportAnnotatedTypeArgumentToUnannotated, getSeverityString(AnnotatedTypeArgumentToUnannotated));
optionsMap.put(OPTION_ReportUnlikelyCollectionMethodArgumentType, getSeverityString(UnlikelyCollectionMethodArgumentType));
optionsMap.put(OPTION_ReportUnlikelyCollectionMethodArgumentTypeStrict, this.reportUnlikelyCollectionMethodArgumentTypeStrict ? ENABLED : DISABLED);
optionsMap.put(OPTION_ReportUnlikelyEqualsArgumentType, getSeverityString(UnlikelyEqualsArgumentType));
@@ -2358,6 +2365,7 @@
this.inheritNullAnnotations = ENABLED.equals(optionValue);
}
if ((optionValue = optionsMap.get(OPTION_ReportNonnullParameterAnnotationDropped)) != null) updateSeverity(NonnullParameterAnnotationDropped, optionValue);
+ if ((optionValue = optionsMap.get(OPTION_ReportAnnotatedTypeArgumentToUnannotated)) != null) updateSeverity(AnnotatedTypeArgumentToUnannotated, optionValue);
if ((optionValue = optionsMap.get(OPTION_PessimisticNullAnalysisForFreeTypeVariables)) != null) updateSeverity(PessimisticNullAnalysisForFreeTypeVariables, optionValue);
if (getSeverity(PessimisticNullAnalysisForFreeTypeVariables) == ProblemSeverities.Ignore) {
this.pessimisticNullAnalysisForFreeTypeVariablesEnabled = false;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java
index 82dd7ad..2bf1799 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java
@@ -143,7 +143,8 @@
// group-2 infos enabled by default
.set(
CompilerOptions.UnlikelyEqualsArgumentType
- | CompilerOptions.SuppressWarningsNotAnalysed);
+ | CompilerOptions.SuppressWarningsNotAnalysed
+ | CompilerOptions.AnnotatedTypeArgumentToUnannotated);
COMPILER_DEFAULT_WARNINGS
//{ObjectTeams: default to warning (group 3):
@@ -235,7 +236,8 @@
.set(CompilerOptions.NonnullParameterAnnotationDropped)
.set(CompilerOptions.MissingNonNullByDefaultAnnotation)
.set(CompilerOptions.PessimisticNullAnalysisForFreeTypeVariables)
- .set(CompilerOptions.NonNullTypeVariableFromLegacyInvocation);
+ .set(CompilerOptions.NonNullTypeVariableFromLegacyInvocation)
+ .set(CompilerOptions.AnnotatedTypeArgumentToUnannotated);
RESTRICTION.set(CompilerOptions.DiscouragedReference);
STATIC_ACCESS.set(CompilerOptions.NonStaticAccessToStatic);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java
index 9d35871..7dd73ba 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java
@@ -1252,6 +1252,11 @@
public void pruneWrapperTrackingVar(FakedTrackingVariable trackingVariable) {
this.trackingVariables.remove(trackingVariable);
}
+
+public boolean hasResourceTrackers() {
+ return this.trackingVariables != null && !this.trackingVariables.isEmpty();
+}
+
/**
* At the end of a block check the closing-status of all tracked closeables that are declared in this block.
* Also invoked when entering unreachable code.
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
index 3500325..9a5e72a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
@@ -3052,7 +3052,7 @@
if ((this.tagBits & TagBits.AreMethodsComplete) != 0)
return super.hasMethodWithNumArgs(selector, numArgs);
// otherwise don't trigger unResolvedMethods() which would actually resolve!
- if (this.scope != null) {
+ if (this.scope != null && this.scope.referenceContext.methods != null) {
for (AbstractMethodDeclaration method : this.scope.referenceContext.methods) {
if (CharOperation.equals(method.selector, TypeConstants.CLOSE)) {
if (numArgs == 0) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/ScannerHelper.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/ScannerHelper.java
index 59ec2cd..8f6b5a8 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/ScannerHelper.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/ScannerHelper.java
@@ -383,10 +383,7 @@
if(c < ScannerHelper.MAX_OBVIOUS) {
return (ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & ScannerHelper.C_DIGIT) != 0;
}
- if (Character.isDigit(c)) {
- throw new InvalidInputException(Scanner.INVALID_DIGIT);
- }
- return false;
+ return Character.isDigit(c);
}
public static int digit(char c, int radix) {
if (c < ScannerHelper.MAX_OBVIOUS) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index 4bd0876..7ed54d0 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -551,6 +551,9 @@
case IProblem.ReferenceExpressionReturnNullRedefUnchecked:
case IProblem.UnsafeNullnessCast:
return CompilerOptions.NullUncheckedConversion;
+ case IProblem.AnnotatedTypeArgumentToUnannotated:
+ case IProblem.AnnotatedTypeArgumentToUnannotatedSuperHint:
+ return CompilerOptions.AnnotatedTypeArgumentToUnannotated;
case IProblem.RedundantNullAnnotation:
case IProblem.RedundantNullDefaultAnnotation:
case IProblem.RedundantNullDefaultAnnotationModule:
@@ -996,6 +999,7 @@
case CompilerOptions.NullUncheckedConversion :
case CompilerOptions.MissingNonNullByDefaultAnnotation:
case CompilerOptions.NonnullParameterAnnotationDropped:
+ case CompilerOptions.AnnotatedTypeArgumentToUnannotated:
return CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM;
case CompilerOptions.RedundantNullAnnotation :
return CategorizedProblem.CAT_UNNECESSARY_CODE;
@@ -15039,6 +15043,7 @@
public void nullityMismatchingTypeAnnotation(Expression expression, TypeBinding providedType, TypeBinding requiredType, NullAnnotationMatching status)
{
if (providedType == requiredType) return; //$IDENTITY-COMPARISON$
+
// try to improve nonnull vs. null:
if (providedType.id == TypeIds.T_null || status.nullStatus == FlowInfo.NULL) {
nullityMismatchIsNull(expression, requiredType);
@@ -15064,17 +15069,21 @@
String superHint = null;
String superHintShort = null;
if (status.superTypeHint != null && requiredType.isParameterizedType()) {
- problemId = (status.isUnchecked()
- ? IProblem.NullityUncheckedTypeAnnotationDetailSuperHint
- : IProblem.NullityMismatchingTypeAnnotationSuperHint);
+ problemId = (status.isAnnotatedToUnannotated()
+ ? IProblem.AnnotatedTypeArgumentToUnannotatedSuperHint
+ : (status.isUnchecked()
+ ? IProblem.NullityUncheckedTypeAnnotationDetailSuperHint
+ : IProblem.NullityMismatchingTypeAnnotationSuperHint));
superHint = status.superTypeHintName(this.options, false);
superHintShort = status.superTypeHintName(this.options, true);
} else {
- problemId = (status.isUnchecked()
- ? IProblem.NullityUncheckedTypeAnnotationDetail
- : (requiredType.isTypeVariable() && !requiredType.hasNullTypeAnnotations())
- ? IProblem.NullityMismatchAgainstFreeTypeVariable
- : IProblem.NullityMismatchingTypeAnnotation);
+ problemId = (status.isAnnotatedToUnannotated()
+ ? IProblem.AnnotatedTypeArgumentToUnannotated
+ : (status.isUnchecked()
+ ? IProblem.NullityUncheckedTypeAnnotationDetail
+ : (requiredType.isTypeVariable() && !requiredType.hasNullTypeAnnotations())
+ ? IProblem.NullityMismatchAgainstFreeTypeVariable
+ : IProblem.NullityMismatchingTypeAnnotation));
if (problemId == IProblem.NullityMismatchAgainstFreeTypeVariable) {
arguments = new String[] { null, null, new String(requiredType.sourceName()) }; // don't show bounds here
shortArguments = new String[] { null, null, new String(requiredType.sourceName()) };
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index 5d3b03f..31bf2a2 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -855,6 +855,8 @@
980 = Unsafe interpretation of method return type as ''@{0}'' based on the receiver type ''{1}''. Type ''{2}'' doesn''t seem to be designed with null type annotations in mind
981 = Unsafe interpretation of method return type as ''@{0}'' based on substitution ''{1}={2}''. Declaring type ''{3}'' doesn''t seem to be designed with null type annotations in mind
982 = Annotation type ''{0}'' cannot be found on the build path, which is implicitly needed for null analysis
+983 = Unsafe null type conversion (type annotations): The value of type ''{1}'' is made accessible using the less-annotated type ''{0}''
+984 = Unsafe null type conversion (type annotations): The value of type ''{1}'' is made accessible using the less-annotated type ''{0}'', corresponding supertype is ''{2}''
# Java 8
1001 = Syntax error, modifiers and annotations are not allowed for the lambda parameter {0} as its type is elided
diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java
index 5206a33..c14ca59 100644
--- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java
+++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java
@@ -877,6 +877,8 @@
return false; // must be handling ast rewrite
if (previous != null && this.tm.countLineBreaksBetween(previous, token) == 0)
return false;
+ if (token.getLineBreaksBefore() == 0 && (previous == null || previous.getLineBreaksAfter() == 0))
+ return false;
int lineStart = token.originalStart;
char c;
while (lineStart > 0 && (c = this.tm.charAt(lineStart - 1)) != '\r' && c != '\n')
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
index 8709a5d..d9dfa9b 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
@@ -2093,7 +2093,22 @@
* @category CompilerOptionID
*/
public static final String COMPILER_PB_NONNULL_TYPEVAR_FROM_LEGACY_INVOCATION = JavaCore.PLUGIN_ID+".compiler.problem.nonnullTypeVariableFromLegacyInvocation"; //$NON-NLS-1$
-
+ /**
+ * Compiler option ID: Reporting Unsafe Conversion To Unannotated Type Argument.
+ * <p>When enabled, the compiler will issue an error, warning or info when a value of a parameterized type
+ * with annotated type arguments is assigned to a variable / bound to a method argument, where the corresponding
+ * type argument is unannotated.</p>
+ * <p>This situation is problematic because it will enable using the less-annotated type to manipulate the given
+ * objects in ways that may violate contracts of the more-annotated type.</p>
+ * <dl>
+ * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated"</code></dd>
+ * <dt>Possible values:</dt><dd><code>{ "error", "warning", "info", "ignore" }</code></dd>
+ * <dt>Default:</dt><dd><code>"info"</code></dd>
+ * </dl>
+ * @since 3.21
+ * @category CompilerOptionID
+ */
+ public static final String COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED = JavaCore.PLUGIN_ID+".compiler.problem.annotatedTypeArgumentToUnannotated"; //$NON-NLS-1$
/**
* Compiler option ID: Setting Source Compatibility Mode.
* <p>Specify whether which source level compatibility is used. From 1.4 on, <code>'assert'</code> is a keyword
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java
index 16561c9..ca2312a 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java
@@ -14,6 +14,7 @@
package org.eclipse.jdt.internal.core;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
@@ -492,8 +493,11 @@
try {
jar = getJar();
ZipEntry mfEntry = jar.getEntry(TypeConstants.META_INF_MANIFEST_MF);
- if (mfEntry != null)
- return new Manifest(jar.getInputStream(mfEntry));
+ if (mfEntry != null) {
+ try (InputStream is = jar.getInputStream(mfEntry)) {
+ return new Manifest(is);
+ }
+ }
} catch (CoreException | IOException e) {
// must do without manifest
} finally {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java
index ca01706..3df9438 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java
@@ -18,6 +18,7 @@
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Arrays;
import java.util.Date;
import java.util.Enumeration;
@@ -394,9 +395,9 @@
if (!scanContent()) // ensure zipFile is initialized
return null;
ZipEntry entry = this.zipFile.getEntry(TypeConstants.META_INF_MANIFEST_MF);
- try {
- if (entry != null)
- return new Manifest(this.zipFile.getInputStream(entry));
+ try(InputStream is = entry != null ? this.zipFile.getInputStream(entry) : null) {
+ if (is != null)
+ return new Manifest(is);
} catch (IOException e) {
// cannot use manifest
}
diff --git a/org.eclipse.jdt.core/plugin.xml b/org.eclipse.jdt.core/plugin.xml
index 315397d..b2365fb 100644
--- a/org.eclipse.jdt.core/plugin.xml
+++ b/org.eclipse.jdt.core/plugin.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<!--
- Copyright (c) 2004, 2014 IBM Corporation and others.
+ Copyright (c) 2004, 2020 IBM Corporation and others.
This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
@@ -13,6 +13,7 @@
Contributors:
IBM Corporation - initial API and implementation
Harry Terkelsen (het@google.com) - Bug 449262 - Allow the use of third-party Java formatters
+ Jonah Graham - Bug 543363 - Move Java Code Formatter to its own bundle
-->
<!-- =================================================================================== -->
@@ -214,17 +215,6 @@
</extension>
<!-- =================================================================================== -->
-<!-- Extension: Java Code Formatter -->
-<!-- =================================================================================== -->
-<extension
- id="JavaCodeFormatter"
- point="org.eclipse.core.runtime.applications">
- <application>
- <run class="org.eclipse.jdt.core.formatter.CodeFormatterApplication" />
- </application>
-</extension>
-
-<!-- =================================================================================== -->
<!-- Extension: Java Generate Indexer -->
<!-- =================================================================================== -->
<extension