Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

prrace
Copy link
Contributor

@prrace prrace commented Nov 13, 2024

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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8344063: Remove doPrivileged calls from swing classes in the java.desktop module (Bug - P4)

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

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 13, 2024

👋 Welcome back prr! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Nov 13, 2024

@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:

8344063: Remove doPrivileged calls from swing classes in the java.desktop module

Reviewed-by: honkar, kcr

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 master branch:

  • 4d4951a: 8343889: Test runtime/cds/appcds/redefineClass/RedefineBasicTest.java failed
  • 697f27c: 8341964: Add mechanism to disable different parts of TLS cipher suite
  • 002b985: 8342963: TestLargeStub::testUpcall doesn't test upcalls stubs
  • e12f514: 8343781: Add since checker test to the Serviceability area modules
  • 7e9dfa4: 8343785: (fs) Remove syscalls that set file times with microsecond precision
  • 68164a4: 8343953: Test jdk/jfr/threading/TestDeepVirtualStackTrace.java fails with Parallel/Serial GC
  • 752e162: 8343877: Test AsyncClose.java intermittent fails - Socket.getInputStream().read() wasn't preempted
  • 4d1a51c: 8344120: Remove Security Manager dependencies from jdk.crypto.cryptoki module
  • a73226b: 8297692: Avoid sending per-region GCPhaseParallel JFR events in G1ScanCollectionSetRegionClosure
  • 6e28cd3: 8343488: Test VectorRebracket128Test.java can't exclude by test/hotspot/jtreg/ProblemList.txt
  • ... and 48 more: https://git.openjdk.org/jdk/compare/63eb4853f6782f350f67b6bcf25d83bc4480be71...master

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot changed the title 8344063 8344063: Remove doPrivileged calls from swing classes in the java.desktop module Nov 13, 2024
@openjdk
Copy link

openjdk bot commented Nov 13, 2024

@prrace The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Nov 13, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 13, 2024
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();
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@mlbridge
Copy link

mlbridge bot commented Nov 13, 2024

Webrevs

Copy link
Contributor

@honkar-jdk honkar-jdk left a 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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 14, 2024
Copy link
Member

@kevinrushforth kevinrushforth left a 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.

Comment on lines -89 to +85
RECONFIGURE_ON_NULL = Boolean.valueOf(
AccessController.doPrivileged(new GetPropertyAction(
"swing.actions.reconfigureOnNull", "false")));
RECONFIGURE_ON_NULL = Boolean.getBoolean("swing.actions.reconfigureOnNull");
Copy link
Member

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

Comment on lines -64 to +69
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);
Copy link
Member

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.

Copy link
Contributor

@altrisi altrisi left a 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(
Copy link
Contributor

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)

Copy link
Member

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.

Copy link
Contributor Author

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();
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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"));
Copy link
Contributor

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).

Copy link
Contributor Author

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

@prrace
Copy link
Contributor Author

prrace commented Nov 14, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Nov 14, 2024

Going to push as commit ec148c1.
Since your change was applied there have been 60 commits pushed to the master branch:

  • 2cbce1f: 8344071: Mark some jdk/jfr/event/oldobject test flagless until they fixed to support all GC
  • 681a57f: 8343064: ClassFormatError: Illegal class name from InnerClassLambdaMetafactory
  • 4d4951a: 8343889: Test runtime/cds/appcds/redefineClass/RedefineBasicTest.java failed
  • 697f27c: 8341964: Add mechanism to disable different parts of TLS cipher suite
  • 002b985: 8342963: TestLargeStub::testUpcall doesn't test upcalls stubs
  • e12f514: 8343781: Add since checker test to the Serviceability area modules
  • 7e9dfa4: 8343785: (fs) Remove syscalls that set file times with microsecond precision
  • 68164a4: 8343953: Test jdk/jfr/threading/TestDeepVirtualStackTrace.java fails with Parallel/Serial GC
  • 752e162: 8343877: Test AsyncClose.java intermittent fails - Socket.getInputStream().read() wasn't preempted
  • 4d1a51c: 8344120: Remove Security Manager dependencies from jdk.crypto.cryptoki module
  • ... and 50 more: https://git.openjdk.org/jdk/compare/63eb4853f6782f350f67b6bcf25d83bc4480be71...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Nov 14, 2024
@openjdk openjdk bot closed this Nov 14, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 14, 2024
@openjdk
Copy link

openjdk bot commented Nov 14, 2024

@prrace Pushed as commit ec148c1.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@@ -211,22 +208,13 @@ public void removeRepaintListener(RepaintManager rm, RepaintListener l) {
}
});

@SuppressWarnings("removal")
var t1 = "true".equals(AccessController.
doPrivileged(new GetPropertyAction(
Copy link
Member

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;
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants