openrewrite / rewrite-static-analysis

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

org.openrewrite.java.migrate.UpgradeToJava17 #373

Open nddipiazza-ebay opened 3 days ago

nddipiazza-ebay commented 3 days 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 3 days 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 2 days 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 day 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