Skip to content

Conversation

satvika-eda
Copy link
Contributor

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

What's changed?

finalize method has been removed from the ZipFile, Deflater and Inflalter of the util package for which the needed automation has been done as part of the recipe created

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)

@satvika-eda satvika-eda changed the title Remove zipfile finalizer Remove finalizer from classes in util.zip Jun 9, 2023
@timtebeek timtebeek self-requested a review June 9, 2023 13:07
@timtebeek timtebeek added the recipe Recipe requested label Jun 9, 2023
@timtebeek
Copy link
Member

Thanks a lot for this recipe @satvika-eda ! I'm adding a link here for context: https://bugs.openjdk.org/browse/JDK-8212129
Reviewing now.

@timtebeek
Copy link
Member

I've gone ahead and added some tests to show some of the potential issues I saw with the current implementation; such as also matching finalize methods called on other classes, and removing the select, which could change side effects. Would you want to work through those issues yourself?

High over I'd say the recipe is not following the typical pattern I'd expect of recipes; right now you're visiting a class declaration, and through that looking through the body, and from there methods and statements. That's rather narrow in terms of what it will match. You're also matching classes and methods based on their name, rather than the types that we set on tree elements, and the matchers we provide.

I'd instead roughly expect a pattern where you first use a Precondition argument to check that any file visited extends Deflater/Inflater/ZipFile, and then as a second argument to Precondition add a visitor that overrides visitMethodInvocation, applies a MethodMatcher for java.util.Object finalize(), and if the methodInvocation.getSelect() matches the class only then return null to remove the method invocation.

I hope all of that is somewhat clear; we really appreciate you providing the initial implementation here, and hope you'll consider making these changes if you feel comfortable doing so.

@timtebeek timtebeek requested a review from joanvr June 23, 2023 11:19
@satvika-eda
Copy link
Contributor Author

satvika-eda commented Jun 23, 2023

Thank you for your valuable inputs.

I've worked on fixing the recipe as per your comments. Please review the PR and provide your inputs. I also made sure all the test cases passed. For "removeCallsToSelfFinalize" test, as finalize() would be called from Object class, before and after would be same as that is not a self finalize as per the recipe.

Support case of empty select by looking at surrounding class declaration
Use method matcher instead of String comparison to find finalize calls
Use TypeUtils instead of String comparison to find extending classes
@timtebeek
Copy link
Member

I've made quite some changes in c6613d1 to have the recipe better fit in with our expected use of OpenRewrite, making use of the type system for comparisons where we can. We now also cover this case, by looking at the surrounding class when finalize is called without a selector Hope you agree with the changes, and thank you for your 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.

2 participants