-
Notifications
You must be signed in to change notification settings - Fork 101
Recipe to remove Thread.countStackFrames()
.
#437
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
Recipe to remove Thread.countStackFrames()
.
#437
Conversation
extra file committed
Hi @ranuradh ; I'm still out for another couple weeks. Probably good to tag Knut for review once @cjobinabo has gone over the changes. |
@Override | ||
public String getDescription() { | ||
return "`Thread.countStackFrames()` has been removed in Java SE 14." + | ||
"It is now replaced by \"Integer.valueOf(\\\"0\\\")\" to return 0." + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably meant for \\\"0\\\"
to be \"0\"
. But the description it's is actually misleading. Thread.countStackFrames()
was not replaced with Integer.valueOf("0")
. Integer.valueOf("0")
is just a placeholder that allows us to safely remove Thread.countStackFrames()
. As I mentioned earlier when we spoke last week, we will need to update this recipe to have a comment before or after the updated code to let the user know they should review and remove the Integer.valueOf("0")
placeholder. @knutwannheden, do you have any examples you could point Anu to on how this comment can be provided, or perhaps a better idea of how Thread.countStackFrames()
could be safely removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how the extra \ got in the description, removed that in the next commit. Based on our conversation I assumed that for now we will be using this format for the recipe, hence added the line "The updated line is dead code and should be eventually removed." I can wait for what @knutwannheden has to say and can update the recipe accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ranuradh I recently learned you can use https://docs.openrewrite.org/recipes/java/migrate/removemethodinvocation for this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjobinabo the recipe only removes the MethodCall where the call's return value is unused. I tried this to remove a constructor. openrewrite/rewrite-static-analysis#273. Hence
import java.lang.Thread;
public class Test {
public static void main(String args[]) {
Thread t1 = new Thread();
Thread t2 = new Thread();
t1.countStackFrames();
t2.countStackFrames();
}
}
will work but the following wont work:
public class Test {
public static void main(String args[]) {
Thread t1 = new Thread();
Thread t2 = new Thread();
int x = t1.countStackFrames();
int y = t2.countStackFrames();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjobinabo as discussed I updated the recipe to now use RemoveMethodInvocation
…hod when its not assigend to a variable
There was a problem hiding this 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/test/java/org/openrewrite/java/migrate/lombok/LombokValueToRecordTest.java
- lines 412-412
There was a problem hiding this 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/test/java/org/openrewrite/java/migrate/lombok/LombokValueToRecordTest.java
- lines 412-412
Hi @timtebeek this recipe is ready for merge |
Thread.countStackFrames()
.
Thread.countStackFrames()
. Thread.countStackFrames()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and minimal; wondering if we should do anything for the cases where it is assigned to a variable, although I'd think those are rare.
Somehow this now fails with
|
…dCountStackFramesMethod
What's changed?
Recipe :org.openrewrite.java.migrate.DeprecatedCountStackFramesMethod

Any additional context
Thread.countStackFrames()
has been removed in Java SE 14 and has been changed in this release to unconditionally throw
UnsupportedOperationException`. This recipe removes the usage of this method in your application as long as the method is not assigned to a variable.Checklist