Skip to content

Security Manager API Removal #713

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

Merged
merged 7 commits into from
May 2, 2025
Merged

Conversation

MBoegers
Copy link
Contributor

What's changed?

With Java 24 the Security Manager API pushes users from using itself. We can help by removing the methods.

What's your motivation?

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@MBoegers MBoegers self-assigned this Apr 30, 2025
@MBoegers MBoegers added the recipe Recipe requested label Apr 30, 2025
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Apr 30, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 1002-1009
    • lines 1033-1042

@MBoegers
Copy link
Contributor Author

MBoegers commented Apr 30, 2025

Other GitHub Examples: full

SecurityManager security = System.getSecurityManager();
if (security != null) {
    try {
        security.checkSystemClipboardAccess();
        clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    } catch (SecurityException e) {
        clipboard = new Clipboard("Application Clipboard");
    }
}

Should become

clipboard = new Clipboard("Application Clipboard");

or

clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

and (original)

SecurityManager sm = System.getSecurityManager();
if (sm != null) sm.checkPermission(new PropertyPermission("user.language", "write"));

Should be removed completely. (bearbeitet)

github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Let's address the comment I posted.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 20-19
    • lines 59-69
    • lines 105-106
    • lines 216-215
    • lines 239-240
    • lines 490-499
    • lines 538-537
    • lines 559-575
    • lines 997-1004
    • lines 1033-1042
    • lines 1092-1110
    • lines 3147-3169
    • lines 3198-3197
    • lines 5616-5625
    • lines 5643-5642
    • lines 5796-5795
    • lines 5831-5832
    • lines 6581-6593
    • lines 6606-6617
    • lines 6631-6630

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 20-19
    • lines 59-69
    • lines 105-106
    • lines 216-215
    • lines 239-240
    • lines 490-499
    • lines 538-537
    • lines 559-575
    • lines 997-1004
    • lines 1033-1042
    • lines 1092-1110
    • lines 3147-3169
    • lines 3198-3197
    • lines 5616-5625
    • lines 5643-5642
    • lines 5796-5795
    • lines 5831-5832
    • lines 6581-6593
    • lines 6606-6617
    • lines 6631-6630

@timtebeek
Copy link
Contributor

I'm seeing here

getSecurityManager used to return the system-wide Security Manager. It now always returns null.

So then can we do the simplest thing here and make that explicit? So going from

SecurityManager security = System.getSecurityManager();
if (security != null) { ... }

To

SecurityManager security = null;
if (security != null) { ... }

That recipe should be very simple to write, and makes explicit what's now implicit. We do a very similar thing in rewrite-feature-flags where we replace the method invocation with a literal, and then call out to other visitors to clean up. Removing that conditional should then happen by default when the variable is always null. Possibly best tackled as a separate PR from the other changes here.

@MBoegers
Copy link
Contributor Author

MBoegers commented May 2, 2025

Yes, a decent option here. I will submit a second PR dealing with Securtity Manager. System.getSecurtityManager() will move to null and then apply existing cleanup recipes.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 20-19
    • lines 59-69
    • lines 105-106
    • lines 216-215
    • lines 239-240
    • lines 490-499
    • lines 538-537
    • lines 559-575
    • lines 997-1004
    • lines 1033-1042
    • lines 1092-1110
    • lines 3147-3169
    • lines 3198-3197
    • lines 5616-5625
    • lines 5643-5642
    • lines 5796-5795
    • lines 5831-5832
    • lines 6581-6593
    • lines 6606-6617
    • lines 6631-6630

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 20-19
    • lines 59-69
    • lines 105-106
    • lines 216-215
    • lines 239-240
    • lines 490-499
    • lines 538-537
    • lines 559-575
    • lines 997-1004
    • lines 1033-1042
    • lines 1092-1110
    • lines 3147-3169
    • lines 3198-3197
    • lines 5616-5625
    • lines 5643-5642
    • lines 5796-5795
    • lines 5831-5832
    • lines 6581-6593
    • lines 6606-6617
    • lines 6631-6630

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks!

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite May 2, 2025
@MBoegers MBoegers merged commit 57d4c64 into main May 2, 2025
2 checks passed
@MBoegers MBoegers deleted the boeg/1115/j24-securtity-manager-removal branch May 2, 2025 13:30
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe requested
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants