Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression')
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java17
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java48
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java284
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java33
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java15
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP323VarLambdaParamsTest.java27
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java14
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java36
8 files changed, 377 insertions, 97 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java
index a62c336c5b..c0e95a3c06 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java
@@ -14,6 +14,8 @@
* bug 376590 - Private fields with @Inject are ignored by unused field validation
* Ulrich Grave <ulrich.grave@gmx.de> - Contributions for
* bug 386692 - Missing "unused" warning on "autowired" fields
+ * Pierre-Yves B. <pyvesdev@gmail.com> - Contribution for
+ * bug 542520 - [JUnit 5] Warning The method xxx from the type X is never used locally is shown when using MethodSource
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -68,6 +70,21 @@ public class AbstractComparableTest extends AbstractRegressionTest {
"\n" +
"}";
+ protected static final String JUNIT_METHODSOURCE_NAME = "org/junit/jupiter/params/provider/MethodSource.java";
+ protected static final String JUNIT_METHODSOURCE_CONTENT =
+ "package org.junit.jupiter.params.provider;\n" +
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import java.lang.annotation.RetentionPolicy;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})\n" +
+ "@Retention(RetentionPolicy.RUNTIME)\n" +
+ "public @interface MethodSource {\n" +
+ "\n" +
+ " String[] value() default \"\";\n" +
+ "\n" +
+ "}";
+
public static Test buildComparableTestSuite(Class evaluationTestClass) {
Test suite = buildMinimalComplianceTestSuite(evaluationTestClass, F_1_5);
TESTS_COUNTERS.put(evaluationTestClass.getName(), Integer.valueOf(suite.countTestCases()));
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
index ec6f7a7b42..01f318f6a7 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -748,8 +748,6 @@ protected static class JavacTestOptions {
}
// WORK consider adding reversed pivots
} : null,
- EclipseBug112433 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=112433
- new EclipseJustification(MismatchType.JavacErrorsEclipseNone) : null,
EclipseBug126712 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=126712 & http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6342411
new EclipseJustification(MismatchType.StandardOutputMismatch) {
Excuse excuseFor(JavacCompiler compiler) {
@@ -802,8 +800,12 @@ protected static class JavacTestOptions {
new EclipseJustification(MismatchType.StandardOutputMismatch) : null;
public static final EclipseJustification
EclipseJustification0001 = RUN_JAVAC ?
- new EclipseJustification(MismatchType.EclipseErrorsJavacNone) : null;
- /* javac properly detects duplicate attributes in annotations in the
+ new EclipseJustification(MismatchType.EclipseErrorsJavacNone) {
+ Excuse excuseFor(JavacCompiler compiler) {
+ return compiler.compliance < ClassFileConstants.JDK1_7 ? this : null;
+ }
+ } : null;
+ /* javac 1.6- properly detects duplicate attributes in annotations in the
* simplest case (AnnotationTest#18b) but fails on a slightly more
* complex one where the duplicate is within an embedded annotation;
* there seems to be no reason for not reporting the error
@@ -928,11 +930,13 @@ protected static class JavacTestOptions {
JavacBug8144673 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8144673
new JavacHasABug(MismatchType.JavacErrorsEclipseNone, ClassFileConstants.JDK9, 0100) : null,
JavacBug8204534 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8204534
- new JavacHasABug(MismatchType.EclipseErrorsJavacNone, ((long)55)<<16, 0000) : null, // FIXME: use JDK11
+ new JavacHasABug(MismatchType.EclipseErrorsJavacNone, ClassFileConstants.JDK11, 0000) : null,
JavacBug8207032 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8207032
new JavacHasABug(MismatchType.EclipseErrorsJavacNone) : null,
JavacBug8044196 = RUN_JAVAC ? // likely https://bugs.openjdk.java.net/browse/JDK-8044196, intermittently masked by https://bugs.openjdk.java.net/browse/JDK-8029161
- new JavacHasABug(MismatchType.EclipseErrorsJavacNone, ClassFileConstants.JDK9, 0000, true) : null;
+ new JavacHasABug(MismatchType.EclipseErrorsJavacNone, ClassFileConstants.JDK9, 0000, true) : null,
+ JavacBug6337964 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=112433
+ new JavacHasABug(MismatchType.JavacErrorsEclipseNone, ClassFileConstants.JDK1_6, 1045/*guessed*/, true) : null;
// bugs that have been fixed but that we've not identified
public static JavacHasABug
@@ -2330,10 +2334,7 @@ protected void runJavac(
// potentially holding indications regarding the failure
if (expectedErrorString != null /* null skips error test */ && mismatch == 0) {
err = adjustErrorOutput(stderr.toString().trim());
- if (!expectedErrorString.equals(err) && // special case: command-line java does not like missing main methods
- !(expectedErrorString.length() == 0 &&
- (err.indexOf("java.lang.NoSuchMethodError: main") != -1)
- || err.indexOf("Error: Main method not found in class") != -1)) {
+ if (!errorStringMatch(expectedErrorString, err)) {
mismatch = JavacTestOptions.MismatchType.ErrorOutputMismatch;
}
}
@@ -2352,6 +2353,28 @@ protected void runJavac(
}
}
}
+private boolean errorStringMatch(String expectedErrorStringStart, String actualError) {
+ /*
+ * From TestVerifier.checkBuffers():
+ * This is an opportunistic heuristic for error strings comparison:
+ * - null means skip test;
+ * - empty means exactly empty;
+ * - other means starts with.
+ * If this became insufficient, we could envision using specific
+ * matchers for specific needs.
+ */
+ if (expectedErrorStringStart == null)
+ return true;
+ // special case: command-line java does not like missing main methods ...
+ if (actualError.indexOf("java.lang.NoSuchMethodError: main") != -1
+ || actualError.indexOf("Error: Main method not found in class") != -1)
+ return true; // ... ignore this.
+ if (expectedErrorStringStart.length() == 0)
+ return expectedErrorStringStart.equals(actualError);
+ if (actualError.startsWith(expectedErrorStringStart))
+ return true;
+ return false;
+}
/** Hook for AbstractRegressionTest9 */
protected String expandFileNameForJavac(String fileName) {
return fileName;
@@ -3030,8 +3053,7 @@ protected void runNegativeTest(boolean skipJavac, JavacTestOptions javacTestOpti
// non-javac part
if (shouldFlushOutputDirectory)
Util.flushDirectoryContent(new File(OUTPUT_DIR));
- // complain early in RUN_JAVAC mode (avoid to do it else until we've fixed all tests)
- if (RUN_JAVAC && testFiles != null && (testFiles.length % 2) != 0) {
+ if (testFiles != null && (testFiles.length % 2) != 0) {
fail("odd number of strings in testFiles");
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
index 51d8632e93..f967c52489 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
@@ -25,6 +25,8 @@
* bug 412153 - [1.8][compiler] Check validity of annotations which may be repeatable
* Ulrich Grave <ulrich.grave@gmx.de> - Contributions for
* bug 386692 - Missing "unused" warning on "autowired" fields
+ * Pierre-Yves B. <pyvesdev@gmail.com> - Contribution for
+ * bug 542520 - [JUnit 5] Warning The method xxx from the type X is never used locally is shown when using MethodSource
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -5010,9 +5012,10 @@ public void test143() {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009
public void test157() {
- Map options = getCompilerOptions();
- options.put(CompilerOptions.OPTION_ReportHiddenCatchBlock, CompilerOptions.WARNING);
- this.runNegativeTest(
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportHiddenCatchBlock, CompilerOptions.WARNING);
+ runner.testFiles =
new String[] {
"X.java",
"public class X {\n" +
@@ -5029,12 +5032,39 @@ public void test143() {
"class AX extends Exception {}\n" +
"@SuppressWarnings({\"serial\"})\n" +
"class BX extends AX {}\n"
- },
- "",
- null,
- true,
- options
- );
+ };
+ runner.javacTestOptions = JavacTestOptions.SKIP; // javac doesn't support @SW("hiding") here, see test157b
+ runner.runConformTest();
+ }
+ public void test157b() {
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportHiddenCatchBlock, CompilerOptions.WARNING);
+ runner.testFiles =
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " try {\n" +
+ " throw new BX();\n" +
+ " } catch(BX e) {\n" +
+ " } catch(AX e) {\n" +
+ " }\n" +
+ " }\n" +
+ "} \n" +
+ "@SuppressWarnings({\"serial\"})\n" +
+ "class AX extends Exception {}\n" +
+ "@SuppressWarnings({\"serial\"})\n" +
+ "class BX extends AX {}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. WARNING in X.java (at line 6)\n" +
+ " } catch(AX e) {\n" +
+ " ^^\n" +
+ "Unreachable catch block for AX. Only more specific exceptions are thrown and they are handled by previous catch block(s).\n" +
+ "----------\n";
+ runner.runWarningTest();
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009
public void test158() {
@@ -5064,9 +5094,10 @@ public void test143() {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009
public void test159() {
- Map options = getCompilerOptions();
- options.put(CompilerOptions.OPTION_ReportIndirectStaticAccess, CompilerOptions.WARNING);
- this.runNegativeTest(
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportIndirectStaticAccess, CompilerOptions.WARNING);
+ runner.testFiles =
new String[] {
"X.java",
"@SuppressWarnings({\"static-access\"})\n" +
@@ -5090,18 +5121,16 @@ public void test143() {
"}\n" +
"class XZ extends XY {\n" +
"}"
- },
- "",
- null,
- true,
- options
- );
+ };
+ runner.javacTestOptions = JavacTestOptions.SKIP; // only testing Eclipse-specific @SW
+ runner.runConformTest();
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009
public void test160() {
- Map options = getCompilerOptions();
- options.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.WARNING);
- this.runNegativeTest(
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.WARNING);
+ runner.testFiles =
new String[] {
"X.java",
"@SuppressWarnings(\"static-access\")\n" +
@@ -5113,12 +5142,9 @@ public void test143() {
"class XY {\n" +
" static int S = 10;\n" +
"}"
- },
- "",
- null,
- true,
- options
- );
+ };
+ runner.javacTestOptions = JavacTestOptions.SKIP; // only testing Eclipse-specific @SW
+ runner.runConformTest();
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009
public void test161() {
@@ -5659,8 +5685,8 @@ public void test143() {
"public class X extends Exception {\n" +
" @SuppressWarnings(\"nls\")\n" +
" String s = \"Hello\"; \n" +
- " @SuppressWarnings(\"serial\")\n" +
- " String s2 = \"Hello2\"; \n" +
+ " @SuppressWarnings(\"serial\")\n" + // no nls-warning here
+ " String s2 = \"Hello2\"; \n" + // but an nls-warning here
"}"
},
null, customOptions,
@@ -5680,7 +5706,7 @@ public void test143() {
" ^^^^^^^^\n" +
"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" +
"----------\n",
- null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings);
+ null, null, JavacTestOptions.SKIP); // nls-warnings are specific to Eclipse - special-casing this special case is irrelevant for javac
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation
public void test172() {
@@ -5749,7 +5775,7 @@ public void test143() {
" ^^^^^^^^\n" +
"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" +
"----------\n",
- null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings);
+ null, null, JavacTestOptions.SKIP); // nls-warnings are specific to Eclipse - special-casing this special case is irrelevant for javac
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation
public void test174() {
@@ -5923,7 +5949,7 @@ public void test143() {
"",
"",
null,
- JavacTestOptions.EclipseJustification.EclipseBug112433);
+ JavacTestOptions.JavacHasABug.JavacBug6337964);
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=116028
public void test180() {
@@ -6656,7 +6682,7 @@ public void test199() {
"",
"",
null,
- JavacTestOptions.EclipseJustification.EclipseBug112433);
+ JavacTestOptions.JavacHasABug.JavacBug6337964);
}
// JLS 3 - 9.6: cannot override Object's methods
public void test200() {
@@ -9367,8 +9393,7 @@ public void test278() {
"----------\n";
this.runNegativeTest(
testString,
- expectedOutput,
- JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+ expectedOutput);
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=301683
public void test279() {
@@ -9392,8 +9417,7 @@ public void test279() {
"----------\n";
this.runNegativeTest(
testString,
- expectedOutput,
- JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+ expectedOutput);
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
public void test280() {
@@ -9869,15 +9893,16 @@ public void test296() {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=343621
public void test297() {
- Map customOptions = getCompilerOptions();
- customOptions.put(CompilerOptions.OPTION_SuppressWarnings, CompilerOptions.ENABLED);
- customOptions.put(CompilerOptions.OPTION_ReportUnhandledWarningToken, CompilerOptions.WARNING);
- customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
- customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
- customOptions.put(CompilerOptions.OPTION_ReportComparingIdentical, CompilerOptions.ERROR);
- customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR);
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(CompilerOptions.OPTION_SuppressWarnings, CompilerOptions.ENABLED);
+ runner.customOptions.put(CompilerOptions.OPTION_ReportUnhandledWarningToken, CompilerOptions.WARNING);
+ runner.customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
+ runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
+ runner.customOptions.put(CompilerOptions.OPTION_ReportComparingIdentical, CompilerOptions.ERROR);
+ runner.customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR);
- String expectedErrors =
+ runner.expectedCompilerLog =
"----------\n" +
"1. ERROR in A.java (at line 15)\n" +
" return i == i;\n" +
@@ -9886,7 +9911,7 @@ public void test297() {
"----------\n";
if (this.complianceLevel >= ClassFileConstants.JDK1_7) {
- expectedErrors =
+ runner.expectedCompilerLog =
"----------\n" +
"1. ERROR in A.java (at line 10)\n" +
" public final Object build(Class<? super Object>... objects) {\n" +
@@ -9899,7 +9924,7 @@ public void test297() {
"Comparing identical expressions\n" +
"----------\n";
}
- String testFiles [] = new String[] {
+ runner.testFiles = new String[] {
"A.java",
"public class A {\n" +
" public void one() {\n" +
@@ -9919,12 +9944,8 @@ public void test297() {
" }\n" +
"}"
};
- runNegativeTest(
- testFiles,
- expectedErrors,
- null,
- true,
- customOptions);
+ runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError;
+ runner.runNegativeTest();
}
// Bug 366003 - CCE in ASTNode.resolveAnnotations(ASTNode.java:639)
// many syntax errors fixed, does not trigger CCE
@@ -10327,7 +10348,7 @@ public void testBug365437b() {
null,
customOptions,
expectedErrorString,
- JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+ isJRE9Plus ? JavacTestOptions.SKIP : JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); // javac9+ cannot access javax.annotation
} finally {
this.javaClassLib = save;
}
@@ -10906,7 +10927,8 @@ public void testBug386356_2() {
" return null;\n" +
" }\n" +
"}"
- });
+ },
+ isJRE9Plus ? JavacTestOptions.SKIP : JavacTestOptions.DEFAULT); // javac9+ cannot access javax.xml.bind
} finally {
this.javaClassLib = save;
}
@@ -11719,11 +11741,12 @@ public void testBug506888a() throws Exception {
if (this.complianceLevel <= ClassFileConstants.JDK1_5) {
return;
}
- Map options = getCompilerOptions();
- options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR);
- options.put(CompilerOptions.OPTION_ReportIncompleteEnumSwitch, CompilerOptions.IGNORE);
- options.put(CompilerOptions.OPTION_ReportMissingDefaultCase, CompilerOptions.WARNING);
- this.runNegativeTest(
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR);
+ runner.customOptions.put(CompilerOptions.OPTION_ReportIncompleteEnumSwitch, CompilerOptions.IGNORE);
+ runner.customOptions.put(CompilerOptions.OPTION_ReportMissingDefaultCase, CompilerOptions.WARNING);
+ runner.testFiles =
new String[] {
"X.java",
"public class X {\n" +
@@ -11732,14 +11755,16 @@ public void testBug506888a() throws Exception {
" void foo() {\n" +
" }\n" +
"} \n",
- },
+ };
+ runner.expectedCompilerLog =
"----------\n" +
"1. INFO in X.java (at line 3)\n" +
" @SuppressWarnings({\"incomplete-switch\"})\n" +
" ^^^^^^^^^^^^^^^^^^^\n" +
"At least one of the problems in category \'incomplete-switch\' is not analysed due to a compiler option being ignored\n" +
- "----------\n",
- null, true, options);
+ "----------\n";
+ runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings;
+ runner.runWarningTest();
}
public void testBug506888b() throws Exception {
if (this.complianceLevel <= ClassFileConstants.JDK1_5) {
@@ -11768,12 +11793,13 @@ public void testBug506888c() throws Exception {
if (this.complianceLevel <= ClassFileConstants.JDK1_5) {
return;
}
- Map options = getCompilerOptions();
- options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.WARNING);
- options.put(CompilerOptions.OPTION_ReportIncompleteEnumSwitch, CompilerOptions.WARNING);
- options.put(CompilerOptions.OPTION_ReportMissingDefaultCase, CompilerOptions.WARNING);
- options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.WARNING);
- this.runNegativeTest(
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.WARNING);
+ runner.customOptions.put(CompilerOptions.OPTION_ReportIncompleteEnumSwitch, CompilerOptions.WARNING);
+ runner.customOptions.put(CompilerOptions.OPTION_ReportMissingDefaultCase, CompilerOptions.WARNING);
+ runner.customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.WARNING);
+ runner.testFiles =
new String[] {
"X.java",
"public class X {\n" +
@@ -11785,14 +11811,16 @@ public void testBug506888c() throws Exception {
" }\n" +
" enum Color { BLUE, RED; } \n" +
"} \n",
- },
+ };
+ runner.expectedCompilerLog =
"----------\n" +
"1. WARNING in X.java (at line 3)\n" +
" @SuppressWarnings({\"incomplete-switch\", \"unchecked\"})\n" +
" ^^^^^^^^^^^\n" +
"Unnecessary @SuppressWarnings(\"unchecked\")\n" +
- "----------\n",
- null, true, options);
+ "----------\n";
+ runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings;
+ runner.runWarningTest();
}
public void testBug506888d() throws Exception {
if (this.complianceLevel <= ClassFileConstants.JDK1_5) {
@@ -11882,7 +11910,7 @@ public void testBug506888f() throws Exception {
null /* vmArguments */,
options,
new Requestor(true, requestor, false, true),
- JavacTestOptions.DEFAULT);
+ JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings);
assertNotNull(requestor.problemArguments);
assertEquals(1, requestor.problemArguments.length);
assertEquals(JavaCore.COMPILER_PB_UNUSED_PARAMETER, requestor.problemArguments[0]);
@@ -11978,4 +12006,114 @@ public void testBug537593_001() {
JavacTestOptions.DEFAULT);
assertNull(requestor.problemArguments);
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=542520 - [JUnit 5] Warning The method xxx from the type X
+// is never used locally is shown when using MethodSource - common case
+public void testBug542520a() throws Exception {
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ runner.testFiles =
+ new String[] {
+ JUNIT_METHODSOURCE_NAME,
+ JUNIT_METHODSOURCE_CONTENT,
+ "ExampleTest.java",
+ "import java.util.Arrays;\n" +
+ "import java.util.List;\n" +
+ "import org.junit.jupiter.params.provider.MethodSource;\n" +
+ "public class ExampleTest {\n" +
+ "\n" +
+ " @MethodSource(\"getIntegers\")\n" +
+ " void testIntegers(Integer integer) {}\n" +
+ " \n" +
+ " private static List<Integer> getIntegers() {\n" +
+ " return Arrays.asList(0, 5, 1);\n" +
+ " }\n" +
+ "}\n",
+ };
+ runner.runConformTest();
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=542520 - [JUnit 5] Warning The method xxx from the type X
+// is never used locally is shown when using MethodSource - variation with fully qualified annotation
+public void testBug542520b() throws Exception {
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ runner.testFiles =
+ new String[] {
+ JUNIT_METHODSOURCE_NAME,
+ JUNIT_METHODSOURCE_CONTENT,
+ "ExampleTest.java",
+ "import java.util.Arrays;\n" +
+ "import java.util.List;\n" +
+ "public class ExampleTest {\n" +
+ "\n" +
+ " @org.junit.jupiter.params.provider.MethodSource(\"getIntegers\")\n" +
+ " void testIntegers(Integer integer) {}\n" +
+ " \n" +
+ " private static List<Integer> getIntegers() {\n" +
+ " return Arrays.asList(0, 5, 1);\n" +
+ " }\n" +
+ "}\n",
+ };
+ runner.runConformTest();
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=542520 - [JUnit 5] Warning The method xxx from the type X
+// is never used locally is shown when using MethodSource - marker annotation
+public void testBug542520c() throws Exception {
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ runner.testFiles =
+ new String[] {
+ JUNIT_METHODSOURCE_NAME,
+ JUNIT_METHODSOURCE_CONTENT,
+ "ExampleTest.java",
+ "import java.util.Arrays;\n" +
+ "import java.util.List;\n" +
+ "import org.junit.jupiter.params.provider.MethodSource;\n" +
+ "public class ExampleTest {\n" +
+ "\n" +
+ " @MethodSource\n" +
+ " void testIntegers(Integer integer) {}\n" +
+ " \n" +
+ " private static List<Integer> testIntegers() {\n" +
+ " return Arrays.asList(0, 5, 1);\n" +
+ " }\n" +
+ "}\n",
+ };
+ runner.runConformTest();
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=542520 - [JUnit 5] Warning The method xxx from the type X
+// is never used locally is shown when using MethodSource - missing no-args method source
+public void testBug542520d() throws Exception {
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ this.runNegativeTest(
+ true,
+ new String[] {
+ JUNIT_METHODSOURCE_NAME,
+ JUNIT_METHODSOURCE_CONTENT,
+ "ExampleTest.java",
+ "import java.util.Arrays;\n" +
+ "import java.util.List;\n" +
+ "import org.junit.jupiter.params.provider.MethodSource;\n" +
+ "public class ExampleTest {\n" +
+ "\n" +
+ " @MethodSource(\"getIntegers\")\n" +
+ " void testIntegers(Integer integer) {}\n" +
+ " \n" +
+ " private static List<Integer> getIntegers(int i) {\n" +
+ " return Arrays.asList(0, 5, 1);\n" +
+ " }\n" +
+ "}\n",
+ },
+ null, customOptions,
+ "----------\n" +
+ "1. ERROR in ExampleTest.java (at line 9)\n" +
+ " private static List<Integer> getIntegers(int i) {\n" +
+ " ^^^^^^^^^^^^^^^^^^\n" +
+ "The method getIntegers(int) from the type ExampleTest is never used locally\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
index 99da258d2d..ca24f35d93 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -6476,5 +6476,36 @@ public void testBug478708() {
"----------\n";
runner.runNegativeTest();
}
+public void testBug543526() {
+ Runner runner = new Runner();
+ runner.testFiles = new String[] {
+ "C.java",
+ "class C {\n" +
+ " <T extends CharSequence & java.util.List<T>> boolean m(T x) {\n" +
+ " return x instanceof String;\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. ERROR in C.java (at line 3)\n" +
+ " return x instanceof String;\n" +
+ " ^^^^^^^^^^^^^^^^^^^\n" +
+ "Incompatible conditional operand types T and String\n" +
+ "----------\n";
+ runner.runNegativeTest();
+}
+public void testBug543526b() {
+ Runner runner = new Runner();
+ runner.testFiles = new String[] {
+ "C.java",
+ "class C {\n" +
+ " <T extends CharSequence & java.util.List<T>> boolean m(T x) {\n" +
+ " return x instanceof Comparable<?>;\n" + // no problem casting to an interface
+ " }\n" +
+ "}\n"
+ };
+ runner.runConformTest();
+}
}
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 8e40010f9d..1979b4bbdd 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2018 GK Software AG, and others.
+ * Copyright (c) 2013, 2019 GK Software AG, and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -9472,4 +9472,17 @@ public void testBug508834_comment0() {
};
runner.runConformTest();
}
+ public void testBug543820() {
+ Runner runner = new Runner();
+ runner.testFiles = new String[] {
+ "A.java",
+ "import java.util.concurrent.atomic.AtomicReference;\n" +
+ "import java.util.Optional;\n" +
+ "public class A {\n" +
+ " private final ThreadLocal<AtomicReference<Optional<Long>>> var =\n" +
+ " ThreadLocal.withInitial(() -> new AtomicReference<>(Optional.empty()));" +
+ "}\n"
+ };
+ runner.runConformTest();
+ }
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP323VarLambdaParamsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP323VarLambdaParamsTest.java
index 5bc4f6e811..1b6fc30645 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP323VarLambdaParamsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP323VarLambdaParamsTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2018 IBM Corporation and others.
+ * Copyright (c) 2018, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -316,4 +316,29 @@ public void testBug536159_04() throws IOException {
"\'var\' is not allowed as an element type of an array\n" +
"----------\n");
}
+public void testBug541532_01() throws IOException {
+ runConformTest(new String[] {
+ "X.java",
+ "import java.util.Arrays;\n" +
+ "import java.util.List;\n" +
+ "\n" +
+ "public class X {\n" +
+ "\n" +
+ " public static void foo(List<String> list) {\n" +
+ " list.stream()\n" +
+ " .map((var s) -> s.toLowerCase())\n" +
+ " .forEach(System.out::println);\n" +
+ "\n" +
+ " list.stream()\n" +
+ " .filter((var s) -> s.length() == 1)\n" +
+ " .forEach(System.out::println);\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " String[] greetings = {\"hello\", \"world\"};\n" +
+ " X.foo(Arrays.asList(greetings));\n" +
+ " }\n" +
+ "}\n"
+ },
+ "hello\nworld");
+}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
index 74b75a5444..65587be739 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016, 2018 IBM Corporation and others.
+ * Copyright (c) 2016, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -383,8 +383,8 @@ public class ModuleCompilationTests extends AbstractBatchCompilerTest {
"----------\n" +
"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 4)\n" +
" java.sql.Connection con = null;\n" +
- " ^^^^^^^^\n" +
- "java.sql cannot be resolved to a type\n" +
+ " ^^^^^^^^^^^^^^^^^^^\n" +
+ "The type java.sql.Connection is not accessible\n" +
"----------\n" +
"1 problem (1 error)\n",
true,
@@ -1959,8 +1959,8 @@ public class ModuleCompilationTests extends AbstractBatchCompilerTest {
"----------\n" +
"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/X.java (at line 2)\n" +
" public class X extends a.A {\n" +
- " ^\n" +
- "a cannot be resolved to a type\n" +
+ " ^^^\n" +
+ "The type a.A is not accessible\n" +
"----------\n" +
"1 problem (1 error)\n",
false,
@@ -2017,8 +2017,8 @@ public class ModuleCompilationTests extends AbstractBatchCompilerTest {
"----------\n" +
"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/X.java (at line 2)\n" +
" public class X extends a.A {\n" +
- " ^\n" +
- "a cannot be resolved to a type\n" +
+ " ^^^\n" +
+ "The type a.A is not accessible\n" +
"----------\n" +
"1 problem (1 error)\n",
false,
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
index 751faf0133..cc7fc5fb1a 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2017 IBM Corporation and others.
+ * Copyright (c) 2005, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -3072,6 +3072,40 @@ public void test526911a() {
};
this.runConformTest(sourceFiles, "1 11", options);
}
+public void testBug533475() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5)
+ return;
+ runConformTest(
+ new String[] {
+ "SwitchBug.java",
+ "public class SwitchBug {\n" +
+ " static class MyClass {\n" +
+ " private static final Object C = \"\";\n" +
+ "\n" +
+ " public enum State {\n" +
+ " ENABLED(C); // pass null constant\n" +
+ "\n" +
+ " State(Object value) {\n" +
+ " } // value can be ignored\n" +
+ " }\n" +
+ "\n" +
+ " /* unused method with switch statement IN SAME CLASS */\n" +
+ " private void unusedMethod() {\n" +
+ " switch (State.ENABLED) {\n" +
+ " case ENABLED:\n" +
+ " break;\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " \n" +
+ " public static void main(String[] args) {\n" +
+ " // access enum values from an other class\n" +
+ " MyClass.State.values();\n" +
+ " System.out.println(\"It runs.\");\n" +
+ " }\n" +
+ "}\n"
+ });
+}
public static Class testClass() {
return SwitchTest.class;
}

Back to the top