Skip to content

Simplify the dead thread-group fallback left by SystemGetSecurityManagerToNull - #1255

Merged
jkschneider merged 2 commits into
java25/spring-boot-parentfrom
java25/security-manager-thread-group
Oct 3, 2026
Merged

jkschneider merged 2 commits into
java25/spring-boot-parentfrom
java25/security-manager-thread-group

Conversation

@jkschneider

Copy link
Copy Markdown
Member

After System.getSecurityManager() becomes null, the common idiom

SecurityManager s = null;
ThreadGroup group = s != null ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();

keeps a dead local and a dead branch; SimplifyConstantIfBranchExecution handles if, not this ternary. New SimplifySecurityManagerThreadGroup, added to the composite right after the replacement: when a null SecurityManager local is used only in the immediately following s != null ? s.getThreadGroup() : <fallback> assignment, drop the local and assign the fallback. Anything with comments, more references or another shape is left alone (the second commit adds the comment guards).

Found by a team of coding agents reviewing a Moderne run of org.openrewrite.java.migrate.UpgradeToJava25 over eight open-source repositories (run 20261003103223-WtyA8). The issue is security-manager-null-local in the run's io.moderne.RecipeIssues data table, and the fix was discussed and reviewed on the run's message board. A row from the table, as a generalized example:

Replacing getSecurityManager with null leaves a dead local and a dead conditional branch. (rrd4j/rrd4j, src/main/java/org/rrd4j/core/RrdSyncThreadPool.java)

Before:

SecurityManager s = System.getSecurityManager();
ThreadGroup group = s != null ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();

What the recipe produced:

SecurityManager s = null;
ThreadGroup group = s != null ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();

Expected:

ThreadGroup group = Thread.currentThread().getThreadGroup();

Stacked on #1254 (6 of 9); merge that one first.

@jkschneider
jkschneider force-pushed the java25/security-manager-thread-group branch from faa05f1 to 9810bb8 Compare October 3, 2026 15:51
@jkschneider
jkschneider merged commit 5d6180e into main Oct 3, 2026
1 check passed
@jkschneider
jkschneider deleted the java25/security-manager-thread-group branch October 3, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant