-
Notifications
You must be signed in to change notification settings - Fork 77
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
Remove Runtime.runFinalizersOnExit()
in upgrade to Java 11
#244
Remove Runtime.runFinalizersOnExit()
in upgrade to Java 11
#244
Conversation
For context: https://bugs.openjdk.org/browse/JDK-8198250 Some of the same review comments from #246 and #247 apply here, such as adding tags, markdown, removing markers. Could you apply those same changes here? Thanks again; really neat to see so many pull requests opened at once! |
""" | ||
class FooBar { | ||
public void test(){ | ||
Runtime.getRuntime().addShutdownHook(new Thread()); |
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.
I think I lack some background on why we inject addShutdownHook(new Thread())
here; do you have a source to explain why that's needed? Seems strange to have an empty Thread run yet still provide value.
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.
I would also like some context here. Can't the method call simply be 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.
Made the following changes : Runtime.getRuntime().addShutdownHook(new Thread(() -> Runtime.getRuntime().exit(0)));
to recipe to exit the JVM as per https://bugs.openjdk.org/browse/JDK-8198250. Let me know your suggestions.
@Getter | ||
public class ReplaceRuntimeFinalizer extends Recipe { | ||
|
||
private static final String METHOD_PATTERN = "runFinalizersOnExit"; |
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.
It would be more idiomatic to add two MethodMatcher
s for java.lang.Runtime runFinalizersOnExit(boolean)
and java.lang.System runFinalizersOnExit(boolean)
. That has the advantage that they will also match if these methods were imported statically.
""" | ||
class FooBar { | ||
public void test(){ | ||
Runtime.getRuntime().addShutdownHook(new Thread()); |
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.
I would also like some context here. Can't the method call simply be 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.
Looking at the referenced documents, I do not understand why we are replacing the method calls for this replacements, instead of just removing them... Maybe you could provide us more context?
Runtime.runFinalizersOnExit()
in upgrade to Java 11
Thanks again @satvika-eda ! I've taken the liberty to use your PR to clean up some duplication we had around removing existing method calls. All of that's now reusable from properties, which should help if there's future such cases. |
What's changed?
Runtime.runFinalizersOnExit() has been removed and replaced in latest JDK versions.
What's your motivation?
To automate JDK migration to a greater extent
Checklist
./gradlew licenseFormat