Skip to content
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 thread destroy method recipe #246

Merged
merged 2 commits into from
Jul 6, 2023

Conversation

satvika-eda
Copy link
Contributor

@satvika-eda satvika-eda commented Jun 27, 2023

What's changed?

To remove Thread.destroy deprecated method

What's your motivation?

To automate JDK migration to a greater extent

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've added the license header to any new files through ./gradlew licenseFormat
  • I've used the IntelliJ auto-formatter on affected files
  • I've updated the documentation (if applicable)

@timtebeek timtebeek added the recipe Recipe requested label Jun 27, 2023
@timtebeek timtebeek self-requested a review June 27, 2023 10:21
@timtebeek
Copy link
Contributor

For context: https://bugs.openjdk.org/browse/JDK-8204260

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 a lot for implementing this one! Some of the same concerns regarding the use of the type system as in #247 apply here, but I don't think there's anything much we can do about that. Some smaller suggestions that when applied can lead to a merge.


@Override
public String getDisplayName() {
return "Remove deprecated Thread.destroy() statement";
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use Markdown around code snippets here and in the description such that it'll look slightly better in the documentation.

Suggested change
return "Remove deprecated Thread.destroy() statement";
return "Remove deprecated `Thread.destroy()`";


@Override
public String getDescription() {
return "Remove deprecated invocations of Thread.destroy() which have no alternatives needed.";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return "Remove deprecated invocations of Thread.destroy() which have no alternatives needed.";
return "Remove deprecated invocations of `Thread.destroy()` which have no alternatives needed.";


@Override
public void defaults(RecipeSpec spec) {
spec.recipe(new RemoveThreadDestroyMethod()).allSources(s -> s.markers(javaVersion(8)));
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't there's anything specific around the Java version of the sources here right? Maybe best to then not explicitly set any markers, as it could cause confusion

Suggested change
spec.recipe(new RemoveThreadDestroyMethod()).allSources(s -> s.markers(javaVersion(8)));
spec.recipe(new RemoveThreadDestroyMethod());

Comment on lines 55 to 56
J.MethodInvocation mi = super.visitMethodInvocation(method, ctx);
return (Objects.nonNull(mi.getSelect()) && TypeUtils.isAssignableTo(JAVA_LANG_THREAD, mi.getSelect().getType()) && mi.getSimpleName().equals("destroy")) ? null : mi;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest to add some newlines here for each of the conditions that we check; and split the ternary into an if statement such that it's clearer that we only make a change (return null) when those conditions match.

Suggested change
J.MethodInvocation mi = super.visitMethodInvocation(method, ctx);
return (Objects.nonNull(mi.getSelect()) && TypeUtils.isAssignableTo(JAVA_LANG_THREAD, mi.getSelect().getType()) && mi.getSimpleName().equals("destroy")) ? null : mi;
J.MethodInvocation mi = super.visitMethodInvocation(method, ctx);
if (Objects.nonNull(mi.getSelect())
&& TypeUtils.isAssignableTo(JAVA_LANG_THREAD, mi.getSelect().getType())
&& mi.getSimpleName().equals("destroy")) {
return null;
}
return mi;

Comment on lines 88 to 89
import java.lang.*;

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import java.lang.*;

@satvika-eda
Copy link
Contributor Author

Thank you for your detailed inputs. I've made the necessary changes. Please review them.

@knutwannheden knutwannheden merged commit 109976e into openrewrite:main Jul 6, 2023
1 check passed
@knutwannheden
Copy link
Contributor

@satvika-eda Thanks for the contribution!

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.

3 participants