Skip to content
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

JDK-8344058 : Remove doPrivileged calls from macos platform sources in the java.desktop module #22159

Closed
wants to merge 1 commit into from

Conversation

honkar-jdk
Copy link
Contributor

@honkar-jdk honkar-jdk commented Nov 15, 2024

Post JEP-486 (Permanently Disable the Security Manager) cleanup.
Calls to java.security.AccessController.doPrivileged are obsolete thus removed in this PR.

This PR addresses removal of AccessController.doPrivileged() calls from macos-platform files in the java.desktop module.Any SM related imports that are no longer needed are removed.

This PR is limited to removing doPrivileged() calls and excludes any refactoring, reformatting, or other clean up that is out-of-scope for this fix.

PS: I have explicitly add comments to the changes where a more watchful review is required.


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-8344058: Remove doPrivileged calls from macos platform sources in the java.desktop module (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22159/head:pull/22159
$ git checkout pull/22159

Update a local copy of the PR:
$ git checkout pull/22159
$ git pull https://git.openjdk.org/jdk.git pull/22159/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22159

View PR using the GUI difftool:
$ git pr show -t 22159

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22159.diff

Using Webrev

Link to Webrev Comment

Sorry, something went wrong.

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 15, 2024

👋 Welcome back honkar! 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 15, 2024

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

8344058: Remove doPrivileged calls from macos platform sources in the java.desktop module

Reviewed-by: prr, aivanov

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 66 new commits pushed to the master branch:

  • 70eb95f: 8344187: Remove SecurityManager and related calls from java.instrument
  • 922b12f: 8344078: Remove security manager dependency in java.nio
  • 2649406: 8344352: 32-bit builds crash after JDK-8305895
  • e9e4200: 8343125: Correct the documentation for TreeMap's getFloorEntry and getCeilingEntry
  • c59adf6: 8344330: Remove AccessController.doPrivileged() from jdk.charsets module
  • c4e7dc7: 8344389: 32-bit builds fail at CDS build time after JDK-8331497
  • d76b5b8: 8344253: Test java/util/Spliterator/SpliteratorTraversingAndSplittingTest.java failed
  • 3e78ff1: 8320743: AEAD ciphers throw undocumented exceptions on overflow
  • 2078329: 8344134: Use static property in SystemLookup
  • 162d66a: 8318668: java/lang/management/MemoryMXBean/CollectionUsageThreshold.java fails with Xcomp
  • ... and 56 more: https://git.openjdk.org/jdk/compare/db56266ad164b4ecae59451dc0a832097dbfbd8e...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
Copy link

openjdk bot commented Nov 15, 2024

@honkar-jdk 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 15, 2024
Comment on lines +147 to +154
ResourceBundle platformResources = null;
try {
platformResources = ResourceBundle.getBundle("sun.awt.resources.awtosx");
} catch (MissingResourceException e) {
// No resource file; defaults will be used.
}

loadLibrary();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In-depth review required here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you are doing is fine.

Unrelated, that System.err.flush() seems odd. I've filed a bug to look at it afterwards since it has NOTHING to do with the doPrivileged.

Comment on lines +170 to +173
private static void loadLibrary() {
System.loadLibrary("awt");
System.loadLibrary("fontmanager");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored System.loadLibrary() calls to a separate static method since they require @SuppressWarnings("restricted") annotation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, because static { .. } doesn't accept an annotation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, That's right.

@@ -151,7 +145,6 @@ public static final boolean isScreenMenuBar(final JMenuBar c) {
public static boolean getScreenMenuBarProperty() {
// Do not allow AWT to set the screen menu bar if it's embedded in another UI toolkit
if (LWCToolkit.isEmbedded()) return false;
return AccessController.doPrivileged(new GetBooleanAction(
AquaLookAndFeel.sPropertyPrefix + "useScreenMenuBar"));
return Boolean.getBoolean(AquaLookAndFeel.sPropertyPrefix + "useScreenMenuBar");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review required

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks OK

@@ -59,8 +59,7 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer {
private static double fMaxImageSize = 128.0;

static {
@SuppressWarnings("removal")
String propValue = java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("apple.awt.dnd.defaultDragImageSize"));
String propValue = System.getProperty("apple.awt.dnd.defaultDragImageSize");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review required

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks ok

@honkar-jdk honkar-jdk marked this pull request as ready for review November 15, 2024 19:18
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 15, 2024
@mlbridge
Copy link

mlbridge bot commented Nov 15, 2024

Webrevs

@@ -151,7 +145,6 @@ public static final boolean isScreenMenuBar(final JMenuBar c) {
public static boolean getScreenMenuBarProperty() {
// Do not allow AWT to set the screen menu bar if it's embedded in another UI toolkit
if (LWCToolkit.isEmbedded()) return false;
return AccessController.doPrivileged(new GetBooleanAction(
AquaLookAndFeel.sPropertyPrefix + "useScreenMenuBar"));
return Boolean.getBoolean(AquaLookAndFeel.sPropertyPrefix + "useScreenMenuBar");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks OK

@@ -59,8 +59,7 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer {
private static double fMaxImageSize = 128.0;

static {
@SuppressWarnings("removal")
String propValue = java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("apple.awt.dnd.defaultDragImageSize"));
String propValue = System.getProperty("apple.awt.dnd.defaultDragImageSize");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks ok

Comment on lines +170 to +173
private static void loadLibrary() {
System.loadLibrary("awt");
System.loadLibrary("fontmanager");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, because static { .. } doesn't accept an annotation.

Comment on lines +147 to +154
ResourceBundle platformResources = null;
try {
platformResources = ResourceBundle.getBundle("sun.awt.resources.awtosx");
} catch (MissingResourceException e) {
// No resource file; defaults will be used.
}

loadLibrary();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you are doing is fine.

Unrelated, that System.err.flush() seems odd. I've filed a bug to look at it afterwards since it has NOTHING to do with the doPrivileged.

@Override
public Boolean run() {
return !Boolean.parseBoolean(
= !Boolean.parseBoolean(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have simplified this to use Boolean.getBoolean() but this is closer to the original so that's fine.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 15, 2024
@honkar-jdk
Copy link
Contributor Author

/integrate

Copy link
Member

@aivanov-jdk aivanov-jdk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good except for a couple of nits.

public class PlatformGraphicsInfo {

static {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
System.loadLibrary("awt");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decrease indentation?

@@ -77,16 +77,10 @@ class CAccessibility implements PropertyChangeListener {
loadAWTLibrary();
}

@SuppressWarnings({"removal", "restricted"})
@SuppressWarnings("restricted")
private static void loadAWTLibrary() {
// Need to load the native library for this code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decrease indentation?

.createSecondaryLoop();
}
});
printingLoop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if you preserved line wrapping, I find it easier to read chained calls in this way.

There's also an extra space after =.

public LWCToolkit() {
final String extraButtons = "sun.awt.enableExtraMouseButtons";
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
areExtraMouseButtonsEnabled =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decrease indentation?

@openjdk
Copy link

openjdk bot commented Nov 18, 2024

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

  • 70eb95f: 8344187: Remove SecurityManager and related calls from java.instrument
  • 922b12f: 8344078: Remove security manager dependency in java.nio
  • 2649406: 8344352: 32-bit builds crash after JDK-8305895
  • e9e4200: 8343125: Correct the documentation for TreeMap's getFloorEntry and getCeilingEntry
  • c59adf6: 8344330: Remove AccessController.doPrivileged() from jdk.charsets module
  • c4e7dc7: 8344389: 32-bit builds fail at CDS build time after JDK-8331497
  • d76b5b8: 8344253: Test java/util/Spliterator/SpliteratorTraversingAndSplittingTest.java failed
  • 3e78ff1: 8320743: AEAD ciphers throw undocumented exceptions on overflow
  • 2078329: 8344134: Use static property in SystemLookup
  • 162d66a: 8318668: java/lang/management/MemoryMXBean/CollectionUsageThreshold.java fails with Xcomp
  • ... and 56 more: https://git.openjdk.org/jdk/compare/db56266ad164b4ecae59451dc0a832097dbfbd8e...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 18, 2024

@honkar-jdk Pushed as commit 92271af.

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

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.

None yet

3 participants