On Mon, 24 Mar 2025 07:53:26 GMT, Robert Stupp <rst...@openjdk.org> wrote:
>> 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`). > > Robert Stupp has updated the pull request with a new target base due to a > merge or a rebase. The pull request now contains three commits: > > - spec (javadoc) > - move checks to CL + hoist IAE checks from URL/BuiltinClassLoaders > - 8349545: ClassLoader.definePackage() throws IllegalArgumentException if > package already defined > > 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. To enable this, > `NamedPackage`, `Package` and `Package$VersionInfo` implement > `hashCode`+`equals`, with the special handling to not involve a > `URLStreamHandler` when comparing `VersionInfo.sealBase`. > > Tests added in `jdk/java/lang/Package/PackageDefineTest.java` (+ pulling > up the `TestClassLoader` from `PackageDefineTest`). Sure, just wanted to prevent it to be closed. I agree, it should not change the behavior in that intrusive way. ------------- PR Comment: https://git.openjdk.org/jdk/pull/23737#issuecomment-2747608911