8336654: [lworld] Tests depending on sun.awt.AppContext can fail when run with migrated classes #22868
+12
−139
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.
The problem is that Boolean will be a value type in the future (Project Valhalla)
and so it can't be the referent of a Reference.
In this code, the abstract class that creates the Reference accepts a generic type so isn't in control of what it receives.
The concrete class that extends the generic class has no idea what the super class implementation does,
so has no way to know that it might do something that is invalid for a value type.
That's an interesting observation for Valhalla (that the code that does something inappropriate for a value type
isn't the source of the value type) but I don't think we need to be concerned
about that here because we can see reasons to do this anyway.
The specific classes exist because a nominal singleton for the VM may need to be private to an AppContext.
This is a concept from applets but also from webstart where we have a single JVM that may be running code
from different origins that needs to be partitioned and sand boxed.
This concept is obsolete now as applets and webstart are no longer supported, and the Security Manager
is disabled, further undermining any way to support partitioning.
This specific case of a Boolean created from the value of a Java System Property looks like it never needed
this partitioning, so the minimal fix is to stop using RecyclableSingleton for it, and just cache the value of that.
The next level of fix is to note that since AppContext is obsolete, there is no need for RecyclableSingleton
to use AppContext specific values, making RecyclableSingleton just a lazy initialization mechanism for the singleton.
Given that removing the obsolete AppContext is on the TBD list - and some JDK components have already
removed per-AppContext code - and we'd probably come back to this in JDK 25 anyway it seems best
to get it over with.
That does mean that one other place in sun.awt.ImageCache needed to be updated too.
Also one test that explicitly checked that AppContexts were used for UI instances is obsolete and removed.
Note that RecyclableSingleton also offers some lazy initialisation benefit, and is widely used in Aqua,
so going further and removing that probably isn't something we want to do at all, and certainly not here.
Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22868/head:pull/22868
$ git checkout pull/22868
Update a local copy of the PR:
$ git checkout pull/22868
$ git pull https://git.openjdk.org/jdk.git pull/22868/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 22868
View PR using the GUI difftool:
$ git pr show -t 22868
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22868.diff
Using Webrev
Link to Webrev Comment