From 708118dbe3f45497824eba3f74d0e1c93553a5ef Mon Sep 17 00:00:00 2001 From: Jiawei_Tang Date: Tue, 24 Oct 2023 16:44:41 +0800 Subject: [PATCH] [EagerAppCDS] fix bug: definePackage should check cld's parent Summary: when call definePackage, it is necessary to check the existed key in its packages and its ancestors' packages Test Plan: jck8d Package003 in JCK-runtime-8d/tests/api/java_lang/ClassLoader/PackageTests.java Reviewed-by: lingjun-cg, yuleil Issue: https://github.com/dragonwell-project/dragonwell8/issues/598 --- jdk/src/share/classes/java/lang/ClassLoader.java | 12 ++++++++---- .../lang/invoke/lambda/LogGeneratedClassesTest.java | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/jdk/src/share/classes/java/lang/ClassLoader.java b/jdk/src/share/classes/java/lang/ClassLoader.java index df3c312834c..9aeb53e324e 100644 --- a/jdk/src/share/classes/java/lang/ClassLoader.java +++ b/jdk/src/share/classes/java/lang/ClassLoader.java @@ -1706,10 +1706,14 @@ protected Package definePackage(String name, String specTitle, throws IllegalArgumentException { Objects.requireNonNull(name); - Package pkg = new Package(name, specTitle, specVersion, specVendor, - implTitle, implVersion, implVendor, - sealBase, this); - if (packages.putIfAbsent(name, pkg) != null) { + Package pkg = getPackage(name); + if (pkg != null) { + throw new IllegalArgumentException(name); + } + final Package new_pkg = new Package(name, specTitle, specVersion, specVendor, + implTitle, implVersion, implVendor, + sealBase, this); + if (packages.computeIfAbsent(name, key -> new_pkg) != new_pkg) { throw new IllegalArgumentException(name); } return pkg; diff --git a/jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java b/jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java index 33acc50d667..a169a3db283 100644 --- a/jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java +++ b/jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java @@ -125,7 +125,8 @@ public void testLogging() throws IOException { "-Djava.security.manager", "com.example.TestLambda"); // dump/com/example + 2 class files - assertEquals(Files.walk(Paths.get("dump")).count(), 5, "Two lambda captured"); + // dump/java/lang + 1 class file + assertEquals(Files.walk(Paths.get("dump")).count(), 8, "Two lambda captured"); tr.assertZero("Should still return 0"); } @@ -236,7 +237,8 @@ public void testLoggingException() throws IOException { .count(), 2, "show error each capture"); // dumpLong/com/example/nosense/nosense - assertEquals(Files.walk(Paths.get("dumpLong")).count(), 5, "Two lambda captured failed to log"); + // dumpLong/java/lang + 1 file + assertEquals(Files.walk(Paths.get("dumpLong")).count(), 8, "Two lambda captured failed to log"); tr.assertZero("Should still return 0"); } }