-
Notifications
You must be signed in to change notification settings - Fork 5.9k
8344063: Remove doPrivileged calls from swing classes in the java.desktop module #22090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👋 Welcome back prr! A progress list of the required criteria for merging this PR into |
@prrace This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 58 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
frame.remove(p.get()); | ||
} | ||
}); | ||
|
||
Util.waitForIdle(null); | ||
//After the next caret blink it automatically TextField references | ||
Thread.sleep(text.get().getCaret().getBlinkRate() * 2); | ||
JTextField tf = text.get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might ask why did this test need to be updated for this change ?
I saw it fail twice - both on Windows, nowhere else - in my various test runs for this PR and so I am being cautious.
Perhaps "timing" is subtly altered, but this test looks buggy to me.
The failure was that the old line 88 got a null referent from text.get() causing an NPE.
After it removes the panel at line 86 above, the text field has no strong ref and could be collected at any time, which would cause the NPE.
I've updated the test to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI to others. I've now seen this test fail in a test of a change that has zero intersection with the changes here.
And another person reported the same for yet another change.
So it seems likely the SM removal is tickling this and I'm surprised it wasn't seen before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a first pass through changes and it looks good. Local build passes with the changes.
Since many files are changed a second pass/review may be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks like what I would expect.
RECONFIGURE_ON_NULL = Boolean.valueOf( | ||
AccessController.doPrivileged(new GetPropertyAction( | ||
"swing.actions.reconfigureOnNull", "false"))); | ||
RECONFIGURE_ON_NULL = Boolean.getBoolean("swing.actions.reconfigureOnNull"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine because the default value you were passing (false) is also the default of Boolean.getBoolean
text = new WeakReference<JTextField>(new JTextField("Text")); | ||
p = new WeakReference<JPanel>(new JPanel(new FlowLayout())); | ||
p.get().add(text.get()); | ||
frame.add(p.get()); | ||
JTextField tf = new JTextField("Text"); | ||
text = new WeakReference<JTextField>(tf); | ||
JPanel jp = new JPanel(new FlowLayout()); | ||
p = new WeakReference<JPanel>(jp); | ||
jp.add(tf); | ||
frame.add(jp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text = new WeakReference<JTextField>(new JTextField("Text"));
p = new WeakReference<JPanel>(new JPanel(new FlowLayout()));
// assume that p.get() and text.get() are always non-null. What coulld go wrong?
p.get().add(text.get());
Well oops. So this is the test failure fix you mentioned offline. This, and the below change, looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a Reviewer, but checked some of the changes.
@@ -211,22 +208,13 @@ public void removeRepaintListener(RepaintManager rm, RepaintListener l) { | |||
} | |||
}); | |||
|
|||
@SuppressWarnings("removal") | |||
var t1 = "true".equals(AccessController. | |||
doPrivileged(new GetPropertyAction( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed the GetPropertyAction import for this file (can't annotate there)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to be a follow-up at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops. I was already integrating when this comment came in.
I will fix in a follow-up.
AWTEventHelper() { | ||
super(); | ||
AccessController.doPrivileged(this); | ||
run(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this method being called run()
still makes sense when just being called from the constructor, it used to make (more) sense when it was an override from PrivilegedAction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that, but I was limiting the changes.
} | ||
} | ||
); | ||
String o = System.getProperty(I18NProperty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the whole handling of I18NProperty
(this line and the if-else below) can be simplified to Boolean.getBoolean, similar to what has been done in other places in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed but I did not want to change the pattern any more than I was forced to, so I left it.
@@ -145,9 +144,7 @@ static boolean isWindows() { | |||
if (!checkedWindows) { | |||
if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) { | |||
isWindows = true; | |||
@SuppressWarnings("removal") | |||
String systemFonts = AccessController.doPrivileged( | |||
new GetPropertyAction("swing.useSystemFontSettings")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed the GetPropertyAction import for this file (can't annotate there).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another one for a follow-up
/integrate |
Going to push as commit ec148c1.
Your commit was automatically rebased without conflicts. |
@@ -211,22 +208,13 @@ public void removeRepaintListener(RepaintManager rm, RepaintListener l) { | |||
} | |||
}); | |||
|
|||
@SuppressWarnings("removal") | |||
var t1 = "true".equals(AccessController. | |||
doPrivileged(new GetPropertyAction( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to be a follow-up at this point.
@@ -32,25 +32,22 @@ | |||
import sun.awt.AppContext; | |||
import sun.awt.SunToolkit; | |||
import sun.awt.event.IgnorePaintEvent; | |||
import sun.security.action.GetBooleanAction; | |||
import sun.security.action.GetPropertyAction; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also remove the now-unused import of AccessController
from this file as a follow-up.
This is the first of a number of PRs to remove doPrivileged uses in client libraries.
These calls are obsolete dead code after JEP 486.
I have run all our automated tests, including JCK tests, and manually tested SwingSet.
One thing I might have missed in a couple of cases is that it seems that javac doesn't seem to notice if you leave an un-needed SuppressWarnings("removal") annotation.
As per the bug report I am limiting (as much as I can) what I touch here to be just the immediate consequences of removing doPrivileged calls. These changes are plenty enough as it is.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22090/head:pull/22090
$ git checkout pull/22090
Update a local copy of the PR:
$ git checkout pull/22090
$ git pull https://git.openjdk.org/jdk.git pull/22090/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 22090
View PR using the GUI difftool:
$ git pr show -t 22090
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22090.diff
Using Webrev
Link to Webrev Comment