RFR: 8349545: ClassLoader.definePackage() throws IllegalArgumentException if package already defined

Robert Stupp rstupp at openjdk.org
Sun Feb 23 15:15:44 UTC 2025


Concurent calls to `ClassLoader.definePackage()` can yield `IllegalArgumentException`s if the package is already defined. Some built-in class loaders, like `URLClassLoader`, already handle this case, but custom class loaders (would) have to handle this case.

This change updates the logic of `CL.definePackage` to not throw an IAE if the "redefined" package is equal to the already defined one.

Tests added in `jdk/java/lang/Package/PackageDefineTest.java` (+ pulling up the `TestClassLoader` from `PackageDefineTest`).

-------------

Commit messages:
 - spec (javadoc)
 - move checks to CL + hoist IAE checks from URL/BuiltinClassLoaders
 - 8349545: ClassLoader.definePackage() throws IllegalArgumentException if package already defined

Changes: https://git.openjdk.org/jdk/pull/23737/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=23737&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8349545
  Stats: 260 lines in 6 files changed: 218 ins; 29 del; 13 mod
  Patch: https://git.openjdk.org/jdk/pull/23737.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/23737/head:pull/23737

PR: https://git.openjdk.org/jdk/pull/23737


More information about the core-libs-dev mailing list