From b4d14540851d792b5366a3723abcea1264a5737c Mon Sep 17 00:00:00 2001 From: "Daniel D. Daugherty" Date: Wed, 22 May 2024 19:06:06 +0000 Subject: [PATCH 1/6] 8332740: [BACKOUT] JDK-8331081 'internal proprietary API' diagnostics if --system is configured to an earlier JDK version Reviewed-by: mikael, prr, jlahoda --- .../com/sun/tools/javac/code/ClassFinder.java | 23 ++-- .../options/system/SystemSunProprietary.java | 127 ------------------ 2 files changed, 9 insertions(+), 141 deletions(-) delete mode 100644 test/langtools/tools/javac/options/system/SystemSunProprietary.java diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java index 972d6a1075b3d..95f8f847923c6 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java @@ -241,7 +241,7 @@ protected ClassFinder(Context context) { * available from the module system. */ long getSupplementaryFlags(ClassSymbol c) { - if (c.name == names.module_info) { + if (jrtIndex == null || !jrtIndex.isInJRT(c.classfile) || c.name == names.module_info) { return 0; } @@ -257,22 +257,17 @@ long getSupplementaryFlags(ClassSymbol c) { try { ModuleSymbol owningModule = packge.modle; if (owningModule == syms.noModule) { - if (jrtIndex != null && jrtIndex.isInJRT(c.classfile)) { - JRTIndex.CtSym ctSym = jrtIndex.getCtSym(packge.flatName()); - Profile minProfile = Profile.DEFAULT; - if (ctSym.proprietary) - newFlags |= PROPRIETARY; - if (ctSym.minProfile != null) - minProfile = Profile.lookup(ctSym.minProfile); - if (profile != Profile.DEFAULT && minProfile.value > profile.value) { - newFlags |= NOT_IN_PROFILE; - } + JRTIndex.CtSym ctSym = jrtIndex.getCtSym(packge.flatName()); + Profile minProfile = Profile.DEFAULT; + if (ctSym.proprietary) + newFlags |= PROPRIETARY; + if (ctSym.minProfile != null) + minProfile = Profile.lookup(ctSym.minProfile); + if (profile != Profile.DEFAULT && minProfile.value > profile.value) { + newFlags |= NOT_IN_PROFILE; } } else if (owningModule.name == names.jdk_unsupported) { newFlags |= PROPRIETARY; - } else { - // don't accumulate user modules in supplementaryFlags - return 0; } } catch (IOException ignore) { } diff --git a/test/langtools/tools/javac/options/system/SystemSunProprietary.java b/test/langtools/tools/javac/options/system/SystemSunProprietary.java deleted file mode 100644 index 0a16305aaba7b..0000000000000 --- a/test/langtools/tools/javac/options/system/SystemSunProprietary.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2024, Alphabet LLC. 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/** - * @test - * @bug 8331081 - * @summary Verify 'internal proprietary API' diagnostics if --system is configured - * @library /tools/lib - * @modules jdk.compiler/com.sun.tools.javac.api jdk.compiler/com.sun.tools.javac.main - * jdk.compiler/com.sun.tools.javac.jvm jdk.jdeps/com.sun.tools.javap - * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavapTask toolbox.TestRunner - * @run main SystemSunProprietary - */ -import toolbox.JavacTask; -import toolbox.Task; -import toolbox.Task.Expect; -import toolbox.TestRunner; -import toolbox.ToolBox; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.List; - -public class SystemSunProprietary extends TestRunner { - - private final ToolBox tb = new ToolBox(); - - public SystemSunProprietary() { - super(System.err); - } - - public static void main(String... args) throws Exception { - new SystemSunProprietary().runTests(); - } - - @Test - public void testUnsafe(Path base) throws IOException { - Path src = base.resolve("src"); - tb.writeJavaFiles( - src, - "module m { requires jdk.unsupported; }", - "package test; public class Test { sun.misc.Unsafe unsafe; } "); - Path classes = base.resolve("classes"); - tb.createDirectories(classes); - - List log; - List expected = - Arrays.asList( - "Test.java:1:43: compiler.warn.sun.proprietary: sun.misc.Unsafe", - "1 warning"); - - log = - new JavacTask(tb) - .options("-XDrawDiagnostics") - .outdir(classes) - .files(tb.findJavaFiles(src)) - .run(Expect.SUCCESS) - .writeAll() - .getOutputLines(Task.OutputKind.DIRECT); - - if (!expected.equals(log)) { - throw new AssertionError("Unexpected output: " + log); - } - - log = - new JavacTask(tb) - .options("-XDrawDiagnostics", "--system", System.getProperty("java.home")) - .outdir(classes) - .files(tb.findJavaFiles(src)) - .run(Expect.SUCCESS) - .writeAll() - .getOutputLines(Task.OutputKind.DIRECT); - - if (!expected.equals(log)) { - throw new AssertionError("Unexpected output: " + log); - } - - // Create a valid argument to system that isn't the current java.home - Path originalSystem = Path.of(System.getProperty("java.home")); - Path system = base.resolve("system"); - for (String path : List.of("release", "lib/modules", "lib/jrt-fs.jar")) { - Path to = system.resolve(path); - Files.createDirectories(to.getParent()); - Files.copy(originalSystem.resolve(path), to); - } - - log = - new JavacTask(tb) - .options("-XDrawDiagnostics", "--system", system.toString()) - .outdir(classes) - .files(tb.findJavaFiles(src)) - .run(Expect.SUCCESS) - .writeAll() - .getOutputLines(Task.OutputKind.DIRECT); - - if (!expected.equals(log)) { - throw new AssertionError("Unexpected output: " + log); - } - } - - protected void runTests() throws Exception { - runTests(m -> new Object[] {Paths.get(m.getName())}); - } -} From d59c12fe1041a1f61f68408241a9aa4d96ac4fd2 Mon Sep 17 00:00:00 2001 From: Nizar Benalla Date: Wed, 22 May 2024 19:13:21 +0000 Subject: [PATCH 2/6] 8329718: Incorrect `@since` tags in elements in jdk.compiler and java.compiler Reviewed-by: darcy, jjg --- .../javax/lang/model/util/ElementKindVisitor14.java | 2 +- .../javax/lang/model/util/ElementScanner6.java | 2 ++ .../javax/tools/ForwardingJavaFileManager.java | 4 ++++ .../share/classes/com/sun/source/tree/CaseTree.java | 11 +++++++---- .../com/sun/source/tree/SwitchExpressionTree.java | 2 +- .../share/classes/com/sun/source/tree/Tree.java | 4 ++-- .../classes/com/sun/source/tree/TreeVisitor.java | 6 ++++-- .../share/classes/com/sun/source/tree/YieldTree.java | 2 +- .../classes/com/sun/source/util/DocTreeScanner.java | 2 ++ .../share/classes/com/sun/source/util/DocTrees.java | 2 ++ .../share/classes/com/sun/source/util/Plugin.java | 2 ++ .../com/sun/source/util/SimpleTreeVisitor.java | 4 ++++ .../classes/com/sun/source/util/TreeScanner.java | 4 ++++ 13 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor14.java b/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor14.java index 919ce5d42563c..28b913ed93d51 100644 --- a/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor14.java +++ b/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor14.java @@ -118,7 +118,7 @@ public R visitTypeAsRecord(TypeElement e, P p) { * @param p {@inheritDoc ElementKindVisitor6} * @return the result of {@code defaultAction} * - * @since 14 + * @since 16 */ @Override public R visitVariableAsBindingVariable(VariableElement e, P p) { diff --git a/src/java.compiler/share/classes/javax/lang/model/util/ElementScanner6.java b/src/java.compiler/share/classes/javax/lang/model/util/ElementScanner6.java index 47a2029d85079..c5bde23b47e1f 100644 --- a/src/java.compiler/share/classes/javax/lang/model/util/ElementScanner6.java +++ b/src/java.compiler/share/classes/javax/lang/model/util/ElementScanner6.java @@ -250,6 +250,8 @@ public R visitTypeParameter(TypeParameterElement e, P p) { * @param e {@inheritDoc ElementVisitor} * @param p {@inheritDoc ElementVisitor} * @return the result of scanning + * + * @since 14 */ @Override public R visitRecordComponent(RecordComponentElement e, P p) { diff --git a/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java b/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java index e0bb999c05b7f..40224abbd509d 100644 --- a/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java +++ b/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java @@ -154,6 +154,8 @@ public JavaFileObject getJavaFileForOutput(Location location, * * @throws IllegalArgumentException {@inheritDoc} * @throws IllegalStateException {@inheritDoc} + * + * @since 18 */ @Override public JavaFileObject getJavaFileForOutputForOriginatingFiles(Location location, @@ -214,6 +216,8 @@ public FileObject getFileForOutput(Location location, * * @throws IllegalArgumentException {@inheritDoc} * @throws IllegalStateException {@inheritDoc} + * + * @since 18 */ @Override public FileObject getFileForOutputForOriginatingFiles(Location location, diff --git a/src/jdk.compiler/share/classes/com/sun/source/tree/CaseTree.java b/src/jdk.compiler/share/classes/com/sun/source/tree/CaseTree.java index facdb8efdafa8..62fa36fa6b7db 100644 --- a/src/jdk.compiler/share/classes/com/sun/source/tree/CaseTree.java +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/CaseTree.java @@ -61,7 +61,8 @@ public interface CaseTree extends Tree { * For default case, returns an empty list. * * @return labels for this case - * @since 12 + * + * @since 14 */ List getExpressions(); @@ -98,7 +99,8 @@ public interface CaseTree extends Tree { * {@linkplain CaseKind#STATEMENT}. * * @return case value or null - * @since 12 + * + * @since 14 */ public default Tree getBody() { return null; @@ -108,7 +110,8 @@ public default Tree getBody() { * Returns the kind of this case. * * @return the kind of this case - * @since 12 + * + * @since 14 */ public default CaseKind getCaseKind() { return CaseKind.STATEMENT; @@ -121,7 +124,7 @@ public default CaseKind getCaseKind() { *
  • RULE: {@code case -> /}
  • * * - * @since 12 + * @since 14 */ public enum CaseKind { /** diff --git a/src/jdk.compiler/share/classes/com/sun/source/tree/SwitchExpressionTree.java b/src/jdk.compiler/share/classes/com/sun/source/tree/SwitchExpressionTree.java index 4a60ea53f99c2..2327c7a3f49e9 100644 --- a/src/jdk.compiler/share/classes/com/sun/source/tree/SwitchExpressionTree.java +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/SwitchExpressionTree.java @@ -39,7 +39,7 @@ * * @jls 15.29 Switch Expressions * - * @since 12 + * @since 14 */ public interface SwitchExpressionTree extends ExpressionTree { /** diff --git a/src/jdk.compiler/share/classes/com/sun/source/tree/Tree.java b/src/jdk.compiler/share/classes/com/sun/source/tree/Tree.java index 0bd3823307b74..4b7df6185d626 100644 --- a/src/jdk.compiler/share/classes/com/sun/source/tree/Tree.java +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/Tree.java @@ -284,7 +284,7 @@ public enum Kind { /** * Used for instances of {@link SwitchExpressionTree}. * - * @since 12 + * @since 14 */ SWITCH_EXPRESSION(SwitchExpressionTree.class), @@ -702,7 +702,7 @@ public enum Kind { /** * Used for instances of {@link YieldTree}. * - * @since 13 + * @since 14 */ YIELD(YieldTree.class); diff --git a/src/jdk.compiler/share/classes/com/sun/source/tree/TreeVisitor.java b/src/jdk.compiler/share/classes/com/sun/source/tree/TreeVisitor.java index 3f7a683350c2e..b7851d8ff9a58 100644 --- a/src/jdk.compiler/share/classes/com/sun/source/tree/TreeVisitor.java +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/TreeVisitor.java @@ -413,7 +413,8 @@ public interface TreeVisitor { * @param node the node being visited * @param p a parameter value * @return a result value - * @since 12 + * + * @since 14 */ R visitSwitchExpression(SwitchExpressionTree node, P p); @@ -608,7 +609,8 @@ public interface TreeVisitor { * @param node the node being visited * @param p a parameter value * @return a result value - * @since 13 + * + * @since 14 */ R visitYield(YieldTree node, P p); } diff --git a/src/jdk.compiler/share/classes/com/sun/source/tree/YieldTree.java b/src/jdk.compiler/share/classes/com/sun/source/tree/YieldTree.java index 181d0495774ea..eeda36d84aed6 100644 --- a/src/jdk.compiler/share/classes/com/sun/source/tree/YieldTree.java +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/YieldTree.java @@ -35,7 +35,7 @@ * * @jls 14.21 The yield Statement * - * @since 13 + * @since 14 */ public interface YieldTree extends StatementTree { diff --git a/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java b/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java index 2dd83d85a5dda..d2d0753dbf287 100644 --- a/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java +++ b/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java @@ -229,6 +229,8 @@ public R visitDocRoot(DocRootTree node, P p) { * @param node {@inheritDoc} * @param p {@inheritDoc} * @return the result of scanning + * + * @since 10 */ @Override public R visitDocType(DocTypeTree node, P p) { diff --git a/src/jdk.compiler/share/classes/com/sun/source/util/DocTrees.java b/src/jdk.compiler/share/classes/com/sun/source/util/DocTrees.java index 6d2e60e58a33c..45a452bd0dd54 100644 --- a/src/jdk.compiler/share/classes/com/sun/source/util/DocTrees.java +++ b/src/jdk.compiler/share/classes/com/sun/source/util/DocTrees.java @@ -276,6 +276,8 @@ public abstract void printMessage(Diagnostic.Kind kind, CharSequence msg, * @param tree the tree containing the entity * @return a string containing the characters * @spec https://www.w3.org/TR/html52 HTML Standard + * + * @since 16 */ public abstract String getCharacters(EntityTree tree); } diff --git a/src/jdk.compiler/share/classes/com/sun/source/util/Plugin.java b/src/jdk.compiler/share/classes/com/sun/source/util/Plugin.java index 9a41396d84d9c..aee626929f4cd 100644 --- a/src/jdk.compiler/share/classes/com/sun/source/util/Plugin.java +++ b/src/jdk.compiler/share/classes/com/sun/source/util/Plugin.java @@ -74,6 +74,8 @@ public interface Plugin { * command-line option. * * @return whether or not this plugin should be automatically started + * + * @since 14 */ default boolean autoStart() { return false; diff --git a/src/jdk.compiler/share/classes/com/sun/source/util/SimpleTreeVisitor.java b/src/jdk.compiler/share/classes/com/sun/source/util/SimpleTreeVisitor.java index 5179061b4bb78..1a123a49faa12 100644 --- a/src/jdk.compiler/share/classes/com/sun/source/util/SimpleTreeVisitor.java +++ b/src/jdk.compiler/share/classes/com/sun/source/util/SimpleTreeVisitor.java @@ -299,6 +299,8 @@ public R visitSwitch(SwitchTree node, P p) { * @param node {@inheritDoc} * @param p {@inheritDoc} * @return the result of {@code defaultAction} + * + * @since 14 */ @Override public R visitSwitchExpression(SwitchExpressionTree node, P p) { @@ -1047,6 +1049,8 @@ public R visitOther(Tree node, P p) { * @param node {@inheritDoc} * @param p {@inheritDoc} * @return the result of {@code defaultAction} + * + * @since 14 */ @Override public R visitYield(YieldTree node, P p) { diff --git a/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java b/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java index 49bec302100e8..4327c6f5f314e 100644 --- a/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java +++ b/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java @@ -376,6 +376,8 @@ public R visitSwitch(SwitchTree node, P p) { * @param node {@inheritDoc} * @param p {@inheritDoc} * @return the result of scanning + * + * @since 14 */ @Override public R visitSwitchExpression(SwitchExpressionTree node, P p) { @@ -1200,6 +1202,8 @@ public R visitErroneous(ErroneousTree node, P p) { * @param node {@inheritDoc} * @param p {@inheritDoc} * @return the result of scanning + * + * @since 14 */ @Override public R visitYield(YieldTree node, P p) { From c4557a7b0db5b55585b4caa7cdec81e1c1093cbc Mon Sep 17 00:00:00 2001 From: Aggelos Biboudis Date: Wed, 22 May 2024 19:48:23 +0000 Subject: [PATCH 3/6] 8332463: Byte conditional pattern case element dominates short constant case element Reviewed-by: vromero --- .../com/sun/tools/javac/comp/Check.java | 6 --- .../PrimitivePatternsSwitchErrors.java | 4 +- .../PrimitivePatternsSwitchErrors.out | 3 +- .../tools/javac/patterns/T8332463a.java | 54 +++++++++++++++++++ .../tools/javac/patterns/T8332463b.java | 40 ++++++++++++++ 5 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 test/langtools/tools/javac/patterns/T8332463a.java create mode 100644 test/langtools/tools/javac/patterns/T8332463b.java diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index fc96eaa0be186..4d9f001273374 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -4818,7 +4818,6 @@ void checkSwitchCaseLabelDominated(JCCaseLabel unconditionalCaseLabel, List ib; - case byte ip -> ip; // Error - dominated! + case byte ip -> ip; // OK - not dominated! }; } diff --git a/test/langtools/tools/javac/patterns/PrimitivePatternsSwitchErrors.out b/test/langtools/tools/javac/patterns/PrimitivePatternsSwitchErrors.out index 1cbf288e774d9..75fd62016a086 100644 --- a/test/langtools/tools/javac/patterns/PrimitivePatternsSwitchErrors.out +++ b/test/langtools/tools/javac/patterns/PrimitivePatternsSwitchErrors.out @@ -1,7 +1,6 @@ PrimitivePatternsSwitchErrors.java:15:18: compiler.err.pattern.dominated PrimitivePatternsSwitchErrors.java:24:18: compiler.err.pattern.dominated PrimitivePatternsSwitchErrors.java:31:24: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.Long) -PrimitivePatternsSwitchErrors.java:62:18: compiler.err.pattern.dominated PrimitivePatternsSwitchErrors.java:70:18: compiler.err.pattern.dominated PrimitivePatternsSwitchErrors.java:78:18: compiler.err.pattern.dominated PrimitivePatternsSwitchErrors.java:84:18: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: long, byte) @@ -44,4 +43,4 @@ PrimitivePatternsSwitchErrors.java:254:16: compiler.err.not.exhaustive PrimitivePatternsSwitchErrors.java:260:16: compiler.err.not.exhaustive - compiler.note.preview.filename: PrimitivePatternsSwitchErrors.java, DEFAULT - compiler.note.preview.recompile -44 errors +43 errors \ No newline at end of file diff --git a/test/langtools/tools/javac/patterns/T8332463a.java b/test/langtools/tools/javac/patterns/T8332463a.java new file mode 100644 index 0000000000000..96aaad86a855b --- /dev/null +++ b/test/langtools/tools/javac/patterns/T8332463a.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8332463 + * @summary Byte conditional pattern case element dominates short constant case element + * @compile --enable-preview --source ${jdk.version} T8332463a.java + */ +public class T8332463a { + public int test2() { + Byte i = (byte) 42; + return switch (i) { + case Byte ib -> 1; + case short s -> 2; + }; + } + + public int test4() { + int i = 42; + return switch (i) { + case Integer ib -> 1; + case byte ip -> 2; + }; + } + + public int test3() { + int i = 42; + return switch (i) { + case Integer ib -> 1; + case (byte) 0 -> 2; + }; + } +} diff --git a/test/langtools/tools/javac/patterns/T8332463b.java b/test/langtools/tools/javac/patterns/T8332463b.java new file mode 100644 index 0000000000000..7956fd31f9f38 --- /dev/null +++ b/test/langtools/tools/javac/patterns/T8332463b.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8332463 + * @summary Byte conditional pattern case element dominates short constant case element + * @enablePreview + * @compile T8332463b.java + * @compile --enable-preview --source ${jdk.version} T8332463b.java + */ +public class T8332463b { + public int test1() { + Byte i = (byte) 42; + return switch (i) { + case Byte ib -> 1; + case (short) 0 -> 2; + }; + } +} From 3d4185a9ce482cc655a4c67f39cb2682b02ae4fe Mon Sep 17 00:00:00 2001 From: Mikhailo Seledtsov Date: Wed, 22 May 2024 20:05:33 +0000 Subject: [PATCH 4/6] 8332739: Problemlist compiler/codecache/CheckLargePages until JDK-8332654 is fixed Reviewed-by: kvn, dcubed --- test/hotspot/jtreg/ProblemList.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt index ffd5eaac1898b..a8cdad8b26810 100644 --- a/test/hotspot/jtreg/ProblemList.txt +++ b/test/hotspot/jtreg/ProblemList.txt @@ -67,6 +67,7 @@ compiler/c2/Test8004741.java 8235801 generic-all compiler/c2/irTests/TestDuplicateBackedge.java 8318904 generic-all compiler/codecache/jmx/PoolsIndependenceTest.java 8264632 macosx-all +compiler/codecache/CheckLargePages.java 8332654 linux-x64 compiler/vectorapi/reshape/TestVectorReinterpret.java 8320897 aix-ppc64,linux-ppc64le compiler/vectorapi/VectorLogicalOpIdentityTest.java 8302459 linux-x64,windows-x64 From 98f6a80852383dcbdad7292b7d269a8547d54d45 Mon Sep 17 00:00:00 2001 From: Jaikiran Pai Date: Thu, 23 May 2024 01:03:19 +0000 Subject: [PATCH 5/6] 8332490: JMH org.openjdk.bench.java.util.zip.InflaterInputStreams.inflaterInputStreamRead OOM Reviewed-by: aturbanov, redestad --- .../openjdk/bench/java/util/zip/InflaterInputStreams.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/micro/org/openjdk/bench/java/util/zip/InflaterInputStreams.java b/test/micro/org/openjdk/bench/java/util/zip/InflaterInputStreams.java index ab6be0e9374e8..33704ad3f9f7d 100644 --- a/test/micro/org/openjdk/bench/java/util/zip/InflaterInputStreams.java +++ b/test/micro/org/openjdk/bench/java/util/zip/InflaterInputStreams.java @@ -108,7 +108,10 @@ public void beforeIteration() throws IOException { @Benchmark public void inflaterInputStreamRead() throws IOException { deflated.reset(); - InflaterInputStream iis = new InflaterInputStream(deflated); - while (iis.read(inflated, 0, inflated.length) != -1); + // We close the InflaterInputStream to release underlying native resources of the Inflater. + // The "deflated" ByteArrayInputStream remains unaffected. + try (InflaterInputStream iis = new InflaterInputStream(deflated)) { + while (iis.read(inflated, 0, inflated.length) != -1); + } } } From 9d332e6591334a71335da65a4dd7b2ed0482b6cb Mon Sep 17 00:00:00 2001 From: Prasanta Sadhukhan Date: Thu, 23 May 2024 04:23:04 +0000 Subject: [PATCH 6/6] 8307193: Several Swing jtreg tests use class.forName on L&F classes Reviewed-by: abhiscxk, prr --- .../swing/JMenuBar/RightLeftOrientation.java | 154 ++++++++++++++++ .../swing/JToolBar/RightLeftOrientation.java | 172 ++++++++++++++++++ 2 files changed, 326 insertions(+) create mode 100644 test/jdk/javax/swing/JMenuBar/RightLeftOrientation.java create mode 100644 test/jdk/javax/swing/JToolBar/RightLeftOrientation.java diff --git a/test/jdk/javax/swing/JMenuBar/RightLeftOrientation.java b/test/jdk/javax/swing/JMenuBar/RightLeftOrientation.java new file mode 100644 index 0000000000000..80779c9ce1d07 --- /dev/null +++ b/test/jdk/javax/swing/JMenuBar/RightLeftOrientation.java @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2007, 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* + * @test + * @bug 4211731 4214512 + * @summary + * This test checks if menu bars lay out correctly when their + * ComponentOrientation property is set to RIGHT_TO_LEFT. This test is + * manual. The tester is asked to compare left-to-right and + * right-to-left menu bars and judge whether they are mirror images of each + * other. + * @library /test/jdk/java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual RightLeftOrientation + */ + +import java.awt.ComponentOrientation; +import java.awt.Point; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.ButtonGroup; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; + +public class RightLeftOrientation { + + static JFrame ltrFrame; + static JFrame rtlFrame; + + private static final String INSTRUCTIONS = """ + This test checks menu bars for correct Right-To-Left Component Orientation. + + You should see two frames, each containing a menu bar. + + One frame will be labelled "Left To Right" and will contain + a menu bar with menus starting on its left side. + The other frame will be labelled "Right To Left" and will + contain a menu bar with menus starting on its right side. + + The test will also contain radio buttons that can be used to set + the look and feel of the menu bars. + For each look and feel, you should compare the two menu + bars and make sure they are mirror images of each other. """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("RTL test Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(30) + .testUI(RightLeftOrientation::createTestUI) + .build() + .awaitAndCheck(); + } + + private static JFrame createTestUI() { + JFrame frame = new JFrame("RightLeftOrientation"); + JPanel panel = new JPanel(); + + ButtonGroup group = new ButtonGroup(); + JRadioButton rb; + ActionListener plafChanger = new PlafChanger(); + + UIManager.LookAndFeelInfo[] lafInfos = UIManager.getInstalledLookAndFeels(); + for (int i = 0; i < lafInfos.length; i++) { + rb = new JRadioButton(lafInfos[i].getName()); + rb.setActionCommand(lafInfos[i].getClassName()); + rb.addActionListener(plafChanger); + group.add(rb); + panel.add(rb); + if (i == 0) { + rb.setSelected(true); + } + } + + frame.add(panel); + + ltrFrame = new JFrame("Left To Right"); + ltrFrame.setJMenuBar(createMenuBar(ComponentOrientation.LEFT_TO_RIGHT)); + ltrFrame.setSize(400, 100); + ltrFrame.setLocation(new Point(10, 10)); + ltrFrame.setVisible(true); + + rtlFrame = new JFrame("Right To Left"); + rtlFrame.setJMenuBar(createMenuBar(ComponentOrientation.RIGHT_TO_LEFT)); + rtlFrame.setSize(400, 100); + rtlFrame.setLocation(new Point(10, 120)); + rtlFrame.setVisible(true); + frame.pack(); + return frame; + } + + static class PlafChanger implements ActionListener { + public void actionPerformed(ActionEvent e) { + String lnfName = e.getActionCommand(); + + try { + UIManager.setLookAndFeel(lnfName); + SwingUtilities.updateComponentTreeUI(ltrFrame); + SwingUtilities.updateComponentTreeUI(rtlFrame); + } + catch (Exception exc) { + System.err.println("Could not load LookAndFeel: " + lnfName); + } + + } + } + + + static JMenuBar createMenuBar(ComponentOrientation o) { + JMenuBar menuBar = new JMenuBar(); + menuBar.setComponentOrientation(o); + + JMenu menu = new JMenu("One"); + menu.setComponentOrientation(o); + menuBar.add(menu); + + menu = new JMenu("Two"); + menu.setComponentOrientation(o); + menuBar.add(menu); + + menu = new JMenu("Three"); + menu.setComponentOrientation(o); + menuBar.add(menu); + + return menuBar; + } + +} diff --git a/test/jdk/javax/swing/JToolBar/RightLeftOrientation.java b/test/jdk/javax/swing/JToolBar/RightLeftOrientation.java new file mode 100644 index 0000000000000..8822a86f79a77 --- /dev/null +++ b/test/jdk/javax/swing/JToolBar/RightLeftOrientation.java @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2007, 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* + * @test + * @bug 4214514 + * @summary + * This test checks if tool bars lay out correctly when their + * ComponentOrientation property is set to RIGHT_TO_LEFT. This test is + * manual. The tester is asked to compare left-to-right and + * right-to-left tool bars and judge whether they are mirror images of each + * other. + * @library /test/jdk/java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual RightLeftOrientation + */ + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.ComponentOrientation; +import java.awt.Container; +import java.awt.Point; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JToolBar; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; + +public class RightLeftOrientation { + + static JFrame ltrFrame; + static JFrame rtlFrame; + + private static final String INSTRUCTIONS = """ + This test checks tool bars for correct Right-To-Left Component Orientation. + + You should see two frames, each containing a tool bar. + + One frame will be labelled "Left To Right" and will contain + a tool bar with buttons starting on its left side. + The other frame will be labelled "Right To Left" and will + contain a tool bar with buttons starting on its right side. + + The test will also contain radio buttons that can be used to set + the look and feel of the tool bars. + For each look and feel, you should compare the two tool bars and + make sure they are mirror images of each other. + You should also drag the tool bars to each corner of the frame + to make sure the docking behavior is consistent between the two frames."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("RTL test Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(RightLeftOrientation::createTestUI) + .build() + .awaitAndCheck(); + } + + private static JFrame createTestUI() { + JFrame frame = new JFrame("RightLeftOrientation"); + JPanel panel = new JPanel(); + + ButtonGroup group = new ButtonGroup(); + JRadioButton rb; + ActionListener plafChanger = new PlafChanger(); + + UIManager.LookAndFeelInfo[] lafInfos = UIManager.getInstalledLookAndFeels(); + for (int i = 0; i < lafInfos.length; i++) { + rb = new JRadioButton(lafInfos[i].getName()); + rb.setActionCommand(lafInfos[i].getClassName()); + rb.addActionListener(plafChanger); + group.add(rb); + panel.add(rb); + if (i == 0) { + rb.setSelected(true); + } + } + + frame.add(panel); + + ltrFrame = new JFrame("Left To Right"); + Container contentPane = ltrFrame.getContentPane(); + contentPane.setLayout(new BorderLayout()); + panel = new JPanel(); + panel.setBackground(Color.white); + contentPane.add("Center",panel); + contentPane.add("North", + createToolBar(ComponentOrientation.LEFT_TO_RIGHT)); + ltrFrame.setSize(400, 140); + ltrFrame.setLocation(new Point(10, 10)); + ltrFrame.setVisible(true); + + rtlFrame = new JFrame("Right To Left"); + contentPane = rtlFrame.getContentPane(); + contentPane.setLayout(new BorderLayout()); + panel = new JPanel(); + panel.setBackground(Color.white); + contentPane.add("Center",panel); + contentPane.add("North", + createToolBar(ComponentOrientation.RIGHT_TO_LEFT)); + rtlFrame.setSize(400, 140); + rtlFrame.setLocation(new Point(420, 10)); + rtlFrame.setVisible(true); + + frame.pack(); + return frame; + } + + static class PlafChanger implements ActionListener { + public void actionPerformed(ActionEvent e) { + String lnfName = e.getActionCommand(); + + try { + UIManager.setLookAndFeel(lnfName); + SwingUtilities.updateComponentTreeUI(ltrFrame); + SwingUtilities.updateComponentTreeUI(rtlFrame); + } + catch (Exception exc) { + System.err.println("Could not load LookAndFeel: " + lnfName); + } + + } + } + + + static JToolBar createToolBar(ComponentOrientation o) { + JToolBar toolBar = new JToolBar(); + toolBar.setComponentOrientation(o); + + JButton button = new JButton("One"); + button.setComponentOrientation(o); + toolBar.add(button); + + button = new JButton("Two"); + button.setComponentOrientation(o); + toolBar.add(button); + + button = new JButton("Three"); + button.setComponentOrientation(o); + toolBar.add(button); + + return toolBar; + } + +}