openrewrite / rewrite-static-analysis

OpenRewrite recipes for identifying and fixing static analysis issues.
Apache License 2.0
32 stars 54 forks source link

org.openrewrite.java.migrate.UpgradeToJava17 #373

Open nddipiazza-ebay opened 1 month ago

nddipiazza-ebay commented 1 month ago

Issue with org.openrewrite.staticanalysis.AddSerialAnnotationToSerialVersionUID

As a result of addressing https://github.com/openrewrite/rewrite-migrate-java/issues/96

@Serial was added to any serialVersionUID field in Serializable classes.

But the import was forgotten resulting in

cannot find symbol
[ERROR]   symbol:   class Serial
melloware commented 1 month ago

Hmm can you provide a reproducer? I am seeing the imports get created in a couple of project I have run it on?

timtebeek commented 1 month ago

Would also help to know what version you're using, and indeed ideally as a failing unit test, as per this example. https://github.com/openrewrite/rewrite-static-analysis/blob/2163f0f05dd6fe7f4762e3486c8f16a9a5787036/src/test/java/org/openrewrite/staticanalysis/AddSerialAnnotationToSerialVersionUIDTest.java#L34-L57

Adding the annotation is directly above adding the annotation, so I wouldn't expect any issue. https://github.com/openrewrite/rewrite-static-analysis/blob/2163f0f05dd6fe7f4762e3486c8f16a9a5787036/src/main/java/org/openrewrite/staticanalysis/AddSerialAnnotationToSerialVersionUID.java#L71-L78

nddipiazza-ebay commented 1 month ago

mvn -U "org.openrewrite.maven:rewrite-maven-plugin:run" "-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:LATEST,org.openrewrite.recipe:rewrite-testing-frameworks:LATEST,org.openrewrite.recipe:rewrite-spring:LATEST" "-Drewrite.activeRecipes=org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration,org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic,org.openrewrite.java.migrate.UpgradeToJava17,org.openrewrite.java.testing.mockito.ReplacePowerMockito,org.openrewrite.maven.RemoveDuplicateDependencies"

result:

image
timtebeek commented 4 weeks ago

That's odd; and what version of Java are you running when you invoke that mvn command above? I wonder if you'd see any improvements if you use Java 17 to run that command instead.