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

Recipes for methods and classes renamed or moved when switching to Java 17 #430

Merged
merged 27 commits into from
Mar 20, 2024

Conversation

ranuradh
Copy link
Contributor

@ranuradh ranuradh commented Mar 11, 2024

This PR contains 4 recipes for Java SE 17 migrations.
They are:

  1. org.openrewrite.java.migrate.RemovedZipFinalizeMethods
    image

  2. org.openrewrite.java.migrate.RemovedSSLSessionGetPeerCertificateChainMethodImpl
    image

  3. org.openrewrite.java.migrate.SunNetSslPackageUnavailable
    image

  4. org.openrewrite.java.migrate.RemovedRMIConnectorServerCredentialTypesConstant
    image

Checklist

  • I've added unit tests to cover both positive and negative cases - Added them where possible
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@ranuradh ranuradh requested review from timtebeek and cjobinabo March 11, 2024 14:34
@timtebeek
Copy link
Contributor

Hi @ranuradh ! Since you last contributed we added some automated code reviews which post comments on PRs. You'll want to apply their suggestions, or make adjustments to ensure there's no new suggestions after your last commit.

ranuradh and others added 3 commits March 11, 2024 10:41
…vailableTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
….java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@ranuradh ranuradh self-assigned this Mar 11, 2024
@ranuradh ranuradh added the recipe Recipe requested label Mar 11, 2024
@timtebeek
Copy link
Contributor

Thanks a lot @ranuradh ! @cjobinabo will you do the first round of review here? Just to be sure it's clear who's in the lead.

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.

Great start; some small touch ups to be applied in bulk from this page:
https://github.com/openrewrite/rewrite-migrate-java/pull/430/files

Other than that I think we can see this through quite quickly if @cjobinabo agrees.

@timtebeek timtebeek changed the title adding 4 recipes + tests for JavaSE 17 Recipes for methods and classes renamed or moved when switching to Java 17 Mar 12, 2024
ranuradh and others added 12 commits March 12, 2024 14:42
Co-authored-by: Tim te Beek <tim@moderne.io>
Co-authored-by: Tim te Beek <tim@moderne.io>
Co-authored-by: Tim te Beek <tim@moderne.io>
…vailableTest.java

Co-authored-by: Tim te Beek <tim@moderne.io>
…vailableTest.java

Co-authored-by: Tim te Beek <tim@moderne.io>
…vailableTest.java

Co-authored-by: Tim te Beek <tim@moderne.io>
….java

Co-authored-by: Tim te Beek <tim@moderne.io>
….java

Co-authored-by: Tim te Beek <tim@moderne.io>
….java

Co-authored-by: Tim te Beek <tim@moderne.io>
….java

Co-authored-by: Tim te Beek <tim@moderne.io>
…vailableTest.java

Co-authored-by: Tim te Beek <tim@moderne.io>
…vailableTest.java

Co-authored-by: Tim te Beek <tim@moderne.io>
@ranuradh
Copy link
Contributor Author

ranuradh commented Mar 12, 2024

@timtebeek I saw all the touch ups and committed them. I took note of not using public in test classes and some formatting. This week @cjobinabo has a tech event that he is attending I think if you review and if we can merge it that will be one less review for him when he gets back. I don't think he will mind it.

@ranuradh
Copy link
Contributor Author

@timtebeek and @cjobinabo can we close and merge this. I thought this was done.Thanks!

@timtebeek
Copy link
Contributor

Ah I had thought @cjobinabo would do the final check, as I'm out for the next couple weeks.

@ranuradh
Copy link
Contributor Author

No worries he is back and should be able to take care of it. See you after a couple of weeks!

Copy link
Contributor

@cjobinabo cjobinabo left a comment

Choose a reason for hiding this comment

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

Thanks for looking into these recipes. I left a few comments about missing tests, wording updates, and issues I noticed with some recipes.

tags:
- java17
recipeList:
- org.openrewrite.java.ReplaceConstantWithAnotherConstant:
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 see a test for this recipe.

Copy link
Contributor Author

@ranuradh ranuradh Mar 18, 2024

Choose a reason for hiding this comment

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

Hi @cjobinabo since it wasnt possible to find a jar/jdk upgrade we decided to not have a test for this.. Refer to our slack conversation

Copy link
Contributor

Choose a reason for hiding this comment

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

The only recipes we discussed on Slack before I left were about the removed finalize method and the removed ConstantBootstraps constructor. Perhaps this is a conversation you had with someone else. If you can't find a jar with the dependencies, I would suggest mocking one up like we have done in the past. I would rarely suggest omitting a test.

`java.util.zip.Inflater` and `java.util.zip.Deflater` as it is no longer available in Java SE 12 and later.
tags:
- java17
recipeList:
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 see a test for this recipe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @cjobinabo since it wasnt possible to find a jar with the issue , we decided to not have a test for this.. Refer to our slack conversation

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a conversation you and I had, or you and Tim? If you couldn't find a jar with the dependency, I would have suggested mocking one up as we have before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was about running tests where we need an older version of Java and we cant get that to work -

so while there's no good way to unit test such recipes, you'll have to trust us that the particular case works when run on Java 8 or 11

newMethodName: end
ignoreDefinition: true
- org.openrewrite.java.ChangeMethodName:
methodPattern: "java.util.ZipFile finalize()"
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be java.util.zip.ZipFile

methodPattern: "java.util.zip.Inflater finalize()"
newMethodName: end
ignoreDefinition: true
matchOverrides: true
Copy link
Contributor

Choose a reason for hiding this comment

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

If we ignore definitions, we shouldn't need to do anything with overrides.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in next commit

name: org.openrewrite.java.migrate.RemovedZipFinalizeMethods
displayName: Remove `finalize` method in `java.util.zip.Zipfile`, `java.util.zip.Inflater` and `java.util.zip.Deflater`
description: >
The `finalize` methods in `java.util.zip.ZipFile` is replaced with `close` method and is replaced by `end` method in
Copy link
Contributor

Choose a reason for hiding this comment

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

methods should be method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in next commit

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.RemovedSSLSessionGetPeerCertificateChainMethodImpl
displayName: Remove `SSLSession.getPeerCertificateChain()` method
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove to Replace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in next commit

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.RemovedRMIConnectorServerCredentialTypesConstant
displayName: Remove `RMIConnectorServer.CREDENTIAL_TYPES` constant
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove to Replace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in next commit

name: org.openrewrite.java.migrate.RemovedRMIConnectorServerCredentialTypesConstant
displayName: Remove `RMIConnectorServer.CREDENTIAL_TYPES` constant
description: >
This recipe replaces `RMIConnectorServer.CREDENTIAL_TYPES` constant with the `RMIConnectorServer.CREDENTIALS_FILTER_PATTERN` constant and a filter pattern.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove extra space between recipe replaces. Also add the before RMIConnectorServer.CREDENTIAL_TYPES

Copy link
Contributor

Choose a reason for hiding this comment

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

The last bit about the pattern and a filter pattern can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in next commit

- java17
recipeList:
- org.openrewrite.java.ReplaceConstantWithAnotherConstant:
existingFullyQualifiedConstantName: javax.management.remote.rmi.RMIConnectorServer.CREDENTIAL_TYPES
Copy link
Contributor

Choose a reason for hiding this comment

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

CREDENTIAL_TYPES should be CREDENTIAL_TYPE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this rule I see the this rule flags references to the RMIConnectorServer.CREDENTIAL_TYPES constant and jmx.remote.rmi.server.credential.types string literal. The RMIConnectorServer.CREDENTIAL_TYPES constant was removed in Java SE 15. The constant can be replaced with the RMIConnectorServer.CREDENTIALS_FILTER_PATTERN constant and a filter pattern.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right. It seems like there may have been a typo in the link I looked at initially.

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.SunNetSslPackageUnavailable
displayName: Remove `com.sun.net.ssl` package
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove to Replace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in next commit

@@ -527,4 +528,42 @@ void lombokBumpedGoingTo17() {
)
);
}

@Test
void removedSSLSessionGetPeerCertificateChainMethodImplTest(){
Copy link
Contributor

@cjobinabo cjobinabo Mar 18, 2024

Choose a reason for hiding this comment

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

If possible, please split each recipe into its own test method.

Copy link
Contributor Author

@ranuradh ranuradh Mar 18, 2024

Choose a reason for hiding this comment

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

Actually I thought unless we had multiple cases it was better to put them in the common Test.java, I could add it to another text if u feel strongly but I went with what I saw in the file.

Copy link
Contributor

Choose a reason for hiding this comment

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

I left the earlier comment here because I thought this test method was attempting to test more than one recipe. But that actually does not appear to be the case, so nothing needs to be changed here.

name: org.openrewrite.java.migrate.RemovedZipFinalizeMethods
displayName: Replace `finalize` method in `java.util.zip.Zipfile`, `java.util.zip.Inflater` and `java.util.zip.Deflater`
description: >
The `finalize` method in `java.util.zip.ZipFile` is replaced with `close` method and is replaced by `end` method in
Copy link
Contributor

Choose a reason for hiding this comment

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

In this sentence, let's add the before close

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in next commit

Copy link
Contributor

@github-actions github-actions bot left a 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/main/java/org/openrewrite/java/migrate/maven/UpdateMavenProjectPropertyJavaVersion.java
    • lines 1-0

Copy link
Contributor

@github-actions github-actions bot left a 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/main/java/org/openrewrite/java/migrate/maven/UpdateMavenProjectPropertyJavaVersion.java
    • lines 1-0

Copy link
Contributor

@cjobinabo cjobinabo left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks again for working on this.

@ranuradh ranuradh merged commit b6cea71 into openrewrite:main Mar 20, 2024
2 checks passed
@ranuradh ranuradh deleted the recipe_RemovedZipFinalizeMethods branch March 20, 2024 12:50
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.

4 participants