diff --git a/jdk/src/share/classes/java/lang/ClassLoader.java b/jdk/src/share/classes/java/lang/ClassLoader.java index df3c312834..9aeb53e324 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;