Repository navigation
Keep the realm's own Package while it defines a class on Java 8 - #170
Merged
Merged
Conversation
Java 8 calls the overridable getPackage(String) while it defines a class or package, so answering from imports or the parent there swaps in a foreign Package and its sealing. The thread-wide guard makes that path answer as in the last release, and the import lookup is skipped when the realm already has the package; do not remove the guard as redundant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Java 8,
URLClassLoader.defineClassandClassLoader.definePackagecall the overridableClassLoader.getPackage(String)to find or verify the package they are defining, so the lookup added for imports and the parent made a realm adopt the imported realm'sPackage(with that jar's manifest attributes) instead of defining its own, made a sealed package in either jar fail withSecurityException: sealing violation, and madedefinePackagethrowIllegalArgumentExceptionfor an imported package. While a class or package is being defined on a thread, every realm'sgetPackage(String)on that thread now answers asClassLoaderdoes, including when the base loader is itself a realm; Java 9 and later use the finalgetDefinedPackagethere and are untouched. Lookups from code running in the realm (Package.getPackage,getPackages) still see packages reached through imports and the parent, and the import lookup is skipped when the realm already has the package. The new tests run on every JDK and fail only on Java 8 without the fix.