From f37596e415196f39ac7bbf148e03ff68938537ed Mon Sep 17 00:00:00 2001 From: Stephan Herrmann Date: Sun, 1 Sep 2024 14:02:08 +0200 Subject: [PATCH] Resolved errors in run.javac mode (#2881) + SuperAfterStatementsTest: new excuse JavacBug8207032 + MarkdownCommentsTest - pass suitable arguments to javac and java - initialize reporting options only in one place (setUp()) - remove unrelated errors for better comparison - fine tune problem severities for better comparison with javac + ModuleCompilationTests - adjust to current error messages from javac + RecordPatternTest: 1 EclipseWarningConfiguredAsError see https://github.com/eclipse-jdt/eclipse.jdt.core/pull/2881 --- .../regression/AbstractRegressionTest.java | 7 +- .../regression/MarkdownCommentsTest.java | 149 ++++++++---------- .../regression/ModuleCompilationTests.java | 8 +- .../regression/RecordPatternTest.java | 8 +- .../regression/SuperAfterStatementsTest.java | 1 + 5 files changed, 86 insertions(+), 87 deletions(-) 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 614019875fd..f4888e59553 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 @@ -1169,7 +1169,7 @@ Excuse excuseFor(JavacCompiler compiler) { JavacBug8204534 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8204534 new JavacHasABug(MismatchType.EclipseErrorsJavacNone, ClassFileConstants.JDK11, 0000) : null, JavacBug8207032 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8207032 - new JavacHasABug(MismatchType.EclipseErrorsJavacNone) : null, + new JavacHasABug(MismatchType.EclipseErrorsJavacNone, ClassFileConstants.JDK11, 0000) : 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, JavacBug6337964 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=112433 @@ -1184,7 +1184,10 @@ Excuse excuseFor(JavacCompiler compiler) { new JavacBug8226510(" --release 12 --enable-preview -Xlint:-preview") : null, JavacBug8299416 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8299416 new JavacBugExtraJavacOptionsPlusMismatch(" --release 20 --enable-preview -Xlint:-preview", - MismatchType.EclipseErrorsJavacNone| MismatchType.EclipseErrorsJavacWarnings) : null; + MismatchType.EclipseErrorsJavacNone| MismatchType.EclipseErrorsJavacWarnings) : null, + JavacBug8336255 = RUN_JAVAC ? // https://bugs.openjdk.org/browse/JDK-8336255 + new JavacBugExtraJavacOptionsPlusMismatch(" --release 23 --enable-preview -Xlint:-preview", + MismatchType.JavacErrorsEclipseNone) : null; // bugs that have been fixed but that we've not identified public static JavacHasABug diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MarkdownCommentsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MarkdownCommentsTest.java index 6e72f9b8468..6b6e77176f5 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MarkdownCommentsTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MarkdownCommentsTest.java @@ -26,14 +26,17 @@ @SuppressWarnings({ "unchecked", "rawtypes" }) public class MarkdownCommentsTest extends JavadocTest { - String docCommentSupport = CompilerOptions.ENABLED; - String reportInvalidJavadoc = CompilerOptions.ERROR; - String reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; - String reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; - String reportMissingJavadocTags = CompilerOptions.ERROR; - String reportMissingJavadocComments = null; - String reportMissingJavadocCommentsVisibility = null; - String reportDeprecation = CompilerOptions.ERROR; + private static final JavacTestOptions JAVAC_TEST_OPTIONS = new JavacTestOptions("--enable-preview -source 23 -Xlint:-preview -Xdoclint"); + private static final String[] VMARGS = new String[] {"--enable-preview"}; + + String docCommentSupport; + String reportInvalidJavadoc; + String reportMissingJavadocDescription; + String reportInvalidJavadocVisibility; + String reportMissingJavadocTags; + String reportMissingJavadocComments; + String reportMissingJavadocCommentsVisibility; + String reportDeprecation; String processAnnotations = null; String reportJavadocDeprecation = null; @@ -105,7 +108,32 @@ protected void setUp() throws Exception { this.reportMissingJavadocComments = CompilerOptions.IGNORE; this.reportMissingJavadocCommentsVisibility = CompilerOptions.PUBLIC; this.reportDeprecation = CompilerOptions.ERROR; - this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + } + + @Override + protected void runConformTest(String[] testFiles, String expectedOutput) { + runConformTest(testFiles, expectedOutput, getCompilerOptions(), VMARGS, JAVAC_TEST_OPTIONS); + } + @Override + protected void runNegativeTest(String[] testFiles, String expectedErrors) { + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedCompilerLog = expectedErrors; + runner.customOptions = getCompilerOptions(); + runner.vmArguments = VMARGS; + runner.javacTestOptions = JAVAC_TEST_OPTIONS; + runner.runNegativeTest(); + } + + void runWarningTest(String[] testFiles, String expectedWarnings) { + this.reportInvalidJavadoc = CompilerOptions.WARNING; + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedCompilerLog = expectedWarnings; + runner.vmArguments = VMARGS; + runner.javacTestOptions = JAVAC_TEST_OPTIONS; + runner.runWarningTest(); } public void test001() { @@ -125,53 +153,41 @@ public int sample(String[] params) { " /// @param parameters array of String\n" + " ^^^^^^^^^^\n" + "Javadoc: Parameter parameters is not declared\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + "----------\n"); } public void test002() { - this.runNegativeTest(new String[] { "X.java", """ + this.runWarningTest(new String[] { "X.java", """ public class X { /// /// @param params /// - public void sample(String[] params) { + public int sample(String[] params) { return 42; } + public static void main(String... args) {} } """, }, "----------\n" + - "1. ERROR in X.java (at line 3)\n" + + "1. WARNING in X.java (at line 3)\n" + " /// @param params\n" + " ^^^^^^\n" + "Javadoc: Description expected after this reference\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " return 42;\n" + - " ^^^^^^^^^^\n" + - "Void methods cannot return a value\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + "----------\n"); } public void test003() { - this.runNegativeTest(new String[] { "X.java", """ + this.runConformTest(new String[] { "X.java", """ public class X { /// /// @param params array of String /// - public void sample(String[] params) { + public int sample(String[] params) { return 42; } + public static void main(String... args) {} } """, }, - - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " return 42;\n" + - " ^^^^^^^^^^\n" + - "Void methods cannot return a value\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + ""); } public void test004() { this.runNegativeTest(new String[] { "X.java", """ @@ -180,7 +196,7 @@ public class X { /// @see #method() /// public void sample() { - return ""; + return; } } """, }, @@ -190,34 +206,22 @@ public void sample() { " /// @see #method()\n" + " ^^^^^^\n" + "Javadoc: The method method() is undefined for the type X\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " return \"\";\n" + - " ^^^^^^^^^^\n" + - "Void methods cannot return a value\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + "----------\n"); } public void test005() { - this.runNegativeTest(new String[] { "X.java", """ + this.runConformTest(new String[] { "X.java", """ public class X { /// /// @see #method() /// public void sample() { - return ""; + return; } protected void method() {} + public static void main(String... args) {} } """, }, - - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " return \"\";\n" + - " ^^^^^^^^^^\n" + - "Void methods cannot return a value\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + ""); } public void test006() { this.runConformTest(new String[] { "X.java", @@ -230,10 +234,7 @@ public static void main(String[] arguments) { protected static void method() {} } """, }, - "Hello", - getCompilerOptions(), - new String[]{"--enable-preview"} - ); + "Hello"); } public void test007() { this.runNegativeTest(new String[] { "X.java", @@ -251,8 +252,7 @@ public static void main(String[] arguments) { " /// @see #method()\n" + " ^^^^^^\n" + "Javadoc: The method method() is undefined for the type X\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + "----------\n"); } public void test008() { this.runNegativeTest(new String[] { "X.java", @@ -270,8 +270,7 @@ public static void main(String[] arguments) { " /// @see #method()\n" + " ^^^^^^\n" + "Javadoc: The method method() is undefined for the type X\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + "----------\n"); } public void test009() { this.runNegativeTest(new String[] { "X.java", @@ -289,8 +288,7 @@ public static void main(String[] arguments) { " //// @see #method()\n" + " ^^^^^^\n" + "Javadoc: The method method() is undefined for the type X\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + "----------\n"); } public void test010() { String bkup = this.reportMissingJavadocTags; @@ -352,7 +350,7 @@ public void test012() { String bkup = this.reportMissingJavadocTags; try { this.reportJavadocDeprecation = CompilerOptions.ERROR; - this.runNegativeTest(new String[] { "X.java", + this.runWarningTest(new String[] { "X.java", """ public class X { /// Some text here without the necessary tags for main method @@ -365,12 +363,11 @@ public static void main(String[] arguments) { } """, }, "----------\n" + - "1. ERROR in X.java (at line 3)\n" + + "1. WARNING in X.java (at line 3)\n" + " /// @param arguments\n" + " ^^^^^^^^^\n" + "Javadoc: Description expected after this reference\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + "----------\n"); } finally { this.reportMissingJavadocTags = bkup; } @@ -439,7 +436,7 @@ public static void main(String[] arguments) { public void test015() { String bkup = this.reportMissingJavadocTags; try { - this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTags = CompilerOptions.IGNORE; this.runNegativeTest(new String[] { "X.java", """ public class X { @@ -456,8 +453,7 @@ public static void main() { " /// Reference to an invalid type [Strings]\n" + " ^^^^^^^\n" + "Javadoc: Strings cannot be resolved to a type\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + "----------\n"); } finally { this.reportMissingJavadocTags = bkup; } @@ -465,7 +461,7 @@ public static void main() { public void test016() { String bkup = this.reportMissingJavadocTags; try { - this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTags = CompilerOptions.IGNORE; this.runNegativeTest(new String[] { "X.java", """ public class X { @@ -482,8 +478,7 @@ public static void main() { " /// Reference to an invalid type [java.langs.Strings]\n" + " ^^^^^^^^^^^^^^^^^^\n" + "Javadoc: java.langs cannot be resolved to a type\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + "----------\n"); } finally { this.reportMissingJavadocTags = bkup; } @@ -491,7 +486,7 @@ public static void main() { public void test017() { String bkup = this.reportMissingJavadocTags; try { - this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTags = CompilerOptions.IGNORE; this.runNegativeTest(new String[] { "X.java", """ public class X { @@ -513,8 +508,7 @@ public static void main() { " /// Reference to an invalid type [Strings] [java.langs.Strings]\n" + " ^^^^^^^^^^^^^^^^^^\n" + "Javadoc: java.langs cannot be resolved to a type\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + "----------\n"); } finally { this.reportMissingJavadocTags = bkup; } @@ -522,7 +516,7 @@ public static void main() { public void test018() { String bkup = this.reportMissingJavadocTags; try { - this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTags = CompilerOptions.IGNORE; this.runNegativeTest(new String[] { "X.java", """ public class X { @@ -539,8 +533,7 @@ public static void main() { " /// Reference to an invalid type [Strings][java.langs.Strings]\n" + " ^^^^^^^^^^^^^^^^^^\n" + "Javadoc: java.langs cannot be resolved to a type\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + "----------\n"); } finally { this.reportMissingJavadocTags = bkup; } @@ -565,8 +558,7 @@ public static void main(String[] args) { " /// Reference to an invalid method in a valid type [charArray()][java.lang.String#toCharArrays()]\n" + " ^^^^^^^^^^^^\n" + "Javadoc: The method toCharArrays() is undefined for the type String\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + "----------\n"); } finally { this.reportMissingJavadocTags = bkup; } @@ -591,8 +583,7 @@ public static void main(String[] args) { " /// Reference to an invalid method in a valid type [\\[\\]][java.lang.String#toCharArrays()]\n" + " ^^^^^^^^^^^^\n" + "Javadoc: The method toCharArrays() is undefined for the type String\n" + - "----------\n", - JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + "----------\n"); } finally { this.reportMissingJavadocTags = bkup; } 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 fcc5a285178..b632f97fdc7 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 @@ -771,7 +771,7 @@ public void test015() { "The type p.X is not accessible\n" + "----------\n" + "1 problem (1 error)\n", - "cannot be resolved", + "does not read it", OUTPUT_DIR + File.separator + out, JavacTestOptions.JavacHasABug.JavacBug8207032); } @@ -1274,7 +1274,7 @@ public void test024() { buffer, "", "option -bootclasspath not supported at compliance level 9 and above\n", - "not allowed"); // when specifying -bootclasspath javac answers: "option --boot-class-path not allowed with target 1.9" (two bugs) + "option --boot-class-path cannot be used together with --release"); // error message has changed between versions, name of option plus reason for illegality can be questioned } public void test025() { File outputDirectory = new File(OUTPUT_DIR); @@ -5426,7 +5426,7 @@ public void testBug522472b() { "The import x.y.z cannot be resolved\n" + "----------\n" + "3 problems (3 errors)\n", - "package conflict"); + "reads package x.y.z from both"); } public void testBug522472d() { File outputDirectory = new File(OUTPUT_DIR); @@ -5502,7 +5502,7 @@ public void testBug522472d() { "The package x.y.z is accessible from more than one module: mod.one, mod.one.a\n" + "----------\n" + "3 problems (3 errors)\n", - "conflict"); + "reads package x.y.z from both"); } public void testIssue2357_001() throws Exception { File outputDirectory = new File(OUTPUT_DIR); diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordPatternTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordPatternTest.java index 9f613093c1c..e0a1f081929 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordPatternTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordPatternTest.java @@ -4422,7 +4422,9 @@ public static void main(String[] args) { public void testIssue1999() { Map options = getCompilerOptions(); options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); - runNegativeTest(new String[] { + runNegativeTest( + true, + new String[] { "X.java", """ interface I { @@ -4454,13 +4456,15 @@ public static void main(String argv[]) { } """ }, + null, + options, "----------\n" + "1. ERROR in X.java (at line 18)\n" + " if (a instanceof A) {} // warn here\n" + " ^^^^^^^^^^^^^^\n" + "The expression of type A is already an instance of type A\n" + "----------\n", - null, true, options); + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); } // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2007 public void testIssue2007() { diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SuperAfterStatementsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SuperAfterStatementsTest.java index fe5f7f35242..cf6755e4cc1 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SuperAfterStatementsTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SuperAfterStatementsTest.java @@ -2018,6 +2018,7 @@ public static void main(String... args) { } """}; runner.expectedOutputString = "f3f1"; + runner.javacTestOptions = JavacTestOptions.JavacHasABug.JavacBug8336255; runner.runConformTest(); } public void testComplexNesting_NOK() {