Skip to content

Commit

Permalink
[EagerAppCDS] fix bug: definePackage should check cld's parent
Browse files Browse the repository at this point in the history
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: #598
  • Loading branch information
jia-wei-tang committed Oct 26, 2023
1 parent 6284cfd commit 708118d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions jdk/src/share/classes/java/lang/ClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -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");
}
}

0 comments on commit 708118d

Please sign in to comment.