Skip to content

Security Manager API Removal#713

Merged
MBoegers merged 7 commits into
mainfrom
boeg/1115/j24-securtity-manager-removal
May 2, 2025
Merged

Security Manager API Removal#713
MBoegers merged 7 commits into
mainfrom
boeg/1115/j24-securtity-manager-removal

Conversation

@MBoegers

Copy link
Copy Markdown
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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

MBoegers commented Apr 30, 2025

Copy link
Copy Markdown
Contributor Author

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)

Comment thread src/main/resources/META-INF/rewrite/java-version-25.yml Outdated
github-actions[bot]

This comment was marked as outdated.

Comment thread src/main/resources/META-INF/rewrite/java-version-25.yml Outdated
github-actions[bot]

This comment was marked as outdated.

Comment thread src/main/resources/META-INF/rewrite/java-version-25.yml

@timtebeek timtebeek left a comment

Copy link
Copy Markdown
Member

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member

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

MBoegers commented May 2, 2025

Copy link
Copy Markdown
Contributor Author

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.

Comment thread src/main/resources/META-INF/rewrite/java-version-25.yml
Comment thread src/main/resources/META-INF/rewrite/java-version-25.yml Outdated

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread src/main/resources/META-INF/rewrite/java-version-25.yml Outdated

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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 timtebeek left a comment

Copy link
Copy Markdown
Member

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