From a6f7089798238e2d0ba5ec168c19acf355403e3d Mon Sep 17 00:00:00 2001 From: Chen Liang Date: Thu, 12 Mar 2026 17:58:06 +0000 Subject: [PATCH] 8379799: Upstream redundant diffs fixed in Valhalla - langtool tests 1 Reviewed-by: vromero --- .../combo/tools/javac/combo/CompilationTestCase.java | 6 +++++- .../lib/combo/tools/javac/combo/Diagnostics.java | 8 +++++++- .../tools/javac/combo/JavacTemplateTestBase.java | 8 ++++++++ .../BridgeShouldHaveNoInteriorAnnotationsTest.java | 4 ++-- test/langtools/tools/javac/diags/CheckExamples.java | 12 +++++++++++- .../tools/javac/launcher/SourceLauncherTest.java | 1 + .../tools/javac/patterns/BreakAndLoops.java | 4 ++-- .../tools/javac/preview/PreviewAutoSuppress.java | 8 +++++--- .../langtools/tools/javac/records/RecordReading.java | 3 +-- .../tools/javac/recovery/ClassBlockExits.java | 4 ++-- test/langtools/tools/javap/T4975569.java | 3 +-- 11 files changed, 45 insertions(+), 16 deletions(-) diff --git a/test/langtools/lib/combo/tools/javac/combo/CompilationTestCase.java b/test/langtools/lib/combo/tools/javac/combo/CompilationTestCase.java index 0760352e23b..c3aa92d1f37 100644 --- a/test/langtools/lib/combo/tools/javac/combo/CompilationTestCase.java +++ b/test/langtools/lib/combo/tools/javac/combo/CompilationTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -112,6 +112,10 @@ public class CompilationTestCase extends JavacTemplateTestBase { assertCompile(expandMarkers(constructs), () -> assertCompileSucceededWithWarning(warning), false); } + protected void assertOKWithWarning(String warning, int numberOfTimes, String... constructs) { + assertCompile(expandMarkers(constructs), () -> assertCompileSucceededWithWarning(warning, numberOfTimes), false); + } + protected void assertFail(String expectedDiag, String... constructs) { assertCompile(expandMarkers(constructs), () -> assertCompileFailed(expectedDiag), false); } diff --git a/test/langtools/lib/combo/tools/javac/combo/Diagnostics.java b/test/langtools/lib/combo/tools/javac/combo/Diagnostics.java index 47f496b5891..87ee54b375a 100644 --- a/test/langtools/lib/combo/tools/javac/combo/Diagnostics.java +++ b/test/langtools/lib/combo/tools/javac/combo/Diagnostics.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -84,6 +84,12 @@ public class Diagnostics implements javax.tools.DiagnosticListener d.getCode().equals(key)); } + public boolean containsWarningKey(String key, int numberOfWarnings) { + return diags.stream() + .filter(d -> d.getKind() == Diagnostic.Kind.WARNING || d.getKind() == Diagnostic.Kind.MANDATORY_WARNING) + .filter(d -> d.getCode().equals(key)).count() == numberOfWarnings; + } + /** Get the error keys */ public List errorKeys() { return diags.stream() diff --git a/test/langtools/lib/combo/tools/javac/combo/JavacTemplateTestBase.java b/test/langtools/lib/combo/tools/javac/combo/JavacTemplateTestBase.java index ed5936210a8..3b4b67e7968 100644 --- a/test/langtools/lib/combo/tools/javac/combo/JavacTemplateTestBase.java +++ b/test/langtools/lib/combo/tools/javac/combo/JavacTemplateTestBase.java @@ -154,6 +154,14 @@ public abstract class JavacTemplateTestBase { } } + protected void assertCompileSucceededWithWarning(String warning, int numberOfWarnings) { + if (diags.errorsFound()) + fail("Expected successful compilation"); + if (!diags.containsWarningKey(warning, numberOfWarnings)) { + fail(String.format("Expected compilation warning with %s, found %s", warning, diags.keys())); + } + } + /** * If the provided boolean is true, assert all previous compiles succeeded, * otherwise assert that a compile failed. diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/BridgeShouldHaveNoInteriorAnnotationsTest.java b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/BridgeShouldHaveNoInteriorAnnotationsTest.java index 0ec1a790d72..3426bfedd30 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/BridgeShouldHaveNoInteriorAnnotationsTest.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/BridgeShouldHaveNoInteriorAnnotationsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -71,7 +71,7 @@ public class BridgeShouldHaveNoInteriorAnnotationsTest }; - // Expected output can't be directly encoded into NestedLambdasCastedTest !!! + // Expected output can't be directly encoded into BridgeShouldHaveNoInteriorAnnotationsTest !!! static class OutputExpectedOnceHolder { public String[] outputs = { "0: #120(): CAST, offset=1, type_index=0, location=[TYPE_ARGUMENT(0)]", diff --git a/test/langtools/tools/javac/diags/CheckExamples.java b/test/langtools/tools/javac/diags/CheckExamples.java index 502f5fa8b88..7a188614080 100644 --- a/test/langtools/tools/javac/diags/CheckExamples.java +++ b/test/langtools/tools/javac/diags/CheckExamples.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -45,12 +45,22 @@ import java.util.*; /** * Check invariants for a set of examples. + * + * READ THIS IF THIS TEST FAILS AFTER ADDING A NEW KEY TO 'compiler.properties': + * The 'examples' subdirectory contains a number of examples which provoke + * the reporting of most of the compiler message keys. + * * -- each example should exactly declare the keys that will be generated when * it is run. + * -- this is done by the "// key:"-comment in each fine. * -- together, the examples should cover the set of resource keys in the * compiler.properties bundle. A list of exceptions may be given in the * not-yet.txt file. Entries on the not-yet.txt list should not be * covered by examples. + * -- some keys are only reported by the compiler when specific options are + * supplied. For the purposes of this test, this can be specified by a + * comment e.g. like this: "// options: -Xlint:empty" + * * When new keys are added to the resource bundle, it is strongly recommended * that corresponding new examples be added here, if at all practical, instead * of simply and lazily being added to the not-yet.txt list. diff --git a/test/langtools/tools/javac/launcher/SourceLauncherTest.java b/test/langtools/tools/javac/launcher/SourceLauncherTest.java index c3c8fb19a1b..d0cf11a0327 100644 --- a/test/langtools/tools/javac/launcher/SourceLauncherTest.java +++ b/test/langtools/tools/javac/launcher/SourceLauncherTest.java @@ -670,6 +670,7 @@ public class SourceLauncherTest extends TestRunner { tb.writeJavaFiles(base, "public class Main { public static void main(String... args) {}}"); String log = new JavaTask(tb) .vmOptions("--source", "21") + .includeStandardOptions(false) // Do not inherit --enable-preview .className(base.resolve("Main.java").toString()) .run(Task.Expect.SUCCESS) .getOutput(Task.OutputKind.STDERR); diff --git a/test/langtools/tools/javac/patterns/BreakAndLoops.java b/test/langtools/tools/javac/patterns/BreakAndLoops.java index 31ad8908f53..777d5ae4f42 100644 --- a/test/langtools/tools/javac/patterns/BreakAndLoops.java +++ b/test/langtools/tools/javac/patterns/BreakAndLoops.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -237,4 +237,4 @@ public class BreakAndLoops extends ComboInstance { return code; } } -} \ No newline at end of file +} diff --git a/test/langtools/tools/javac/preview/PreviewAutoSuppress.java b/test/langtools/tools/javac/preview/PreviewAutoSuppress.java index 058ccdf0a2a..f2096aff648 100644 --- a/test/langtools/tools/javac/preview/PreviewAutoSuppress.java +++ b/test/langtools/tools/javac/preview/PreviewAutoSuppress.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,6 +44,8 @@ import java.nio.file.Paths; import java.util.List; public class PreviewAutoSuppress extends TestRunner { + // Major version number (e.g. '27'). + private static final String FEATURE_VERSION = String.valueOf(Runtime.version().feature()); protected ToolBox tb; @@ -83,7 +85,7 @@ public class PreviewAutoSuppress extends TestRunner { List log = new JavacTask(tb, Task.Mode.CMDLINE) .outdir(classes) .options("--enable-preview", - "-source", String.valueOf(Runtime.version().feature()), + "-source", FEATURE_VERSION, "-Xlint:preview", "-XDforcePreview", "-XDrawDiagnostics") @@ -182,7 +184,7 @@ public class PreviewAutoSuppress extends TestRunner { "--add-exports", "java.base/preview.api=ALL-UNNAMED", "--enable-preview", "-Xlint:preview", - "-source", String.valueOf(Runtime.version().feature()), + "-source", FEATURE_VERSION, "-XDrawDiagnostics") .files(tb.findJavaFiles(testSrc)) .run() diff --git a/test/langtools/tools/javac/records/RecordReading.java b/test/langtools/tools/javac/records/RecordReading.java index 6133a04fca9..e57a7f77ceb 100644 --- a/test/langtools/tools/javac/records/RecordReading.java +++ b/test/langtools/tools/javac/records/RecordReading.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,7 +31,6 @@ * @run main RecordReading */ - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; diff --git a/test/langtools/tools/javac/recovery/ClassBlockExits.java b/test/langtools/tools/javac/recovery/ClassBlockExits.java index b1c54b456ae..3ac04cbe991 100644 --- a/test/langtools/tools/javac/recovery/ClassBlockExits.java +++ b/test/langtools/tools/javac/recovery/ClassBlockExits.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -138,4 +138,4 @@ public class ClassBlockExits extends ComboInstance { return code; } } -} \ No newline at end of file +} diff --git a/test/langtools/tools/javap/T4975569.java b/test/langtools/tools/javap/T4975569.java index c43598b41db..ce75ba84586 100644 --- a/test/langtools/tools/javap/T4975569.java +++ b/test/langtools/tools/javap/T4975569.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -105,4 +105,3 @@ public class T4975569 { protected class Prot { } private class Priv { int i; } } -