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 25, 2023
1 parent 6284cfd commit 6b1f053
Showing 1 changed file with 8 additions and 4 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

0 comments on commit 6b1f053

Please sign in to comment.