rewrite-static-analysis icon indicating copy to clipboard operation
rewrite-static-analysis copied to clipboard

Add @Serial annotation to serialVersionUID not working

Open melloware opened this issue 1 year ago • 5 comments

Using the latest version of this recipe: https://docs.openrewrite.org/recipes/staticanalysis/addserialannotationtoserialversionuid

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-static-analysis:RELEASE -Drewrite.activeRecipes=org.openrewrite.staticanalysis.AddSerialAnnotationToserialVersionUID -Drewrite.exportDatatables=true

Just tested that Standalone on two Java projects and it did not add the annotation to any private static final long serialVersionUID = 1L;

Does it do some detection that the pom.xml is already Java14 or higher? Because we are trying to run this as part of the JDK17 Recipe?

melloware avatar Sep 24 '24 21:09 melloware

hi! The recipe does indeed require that you're running at least Java 17, as determined by a marker that we upgrade as part of a Java version bump. Linking the relevant components here.

https://github.com/openrewrite/rewrite-static-analysis/blob/5c43d9487304d136f612c3273d5fb09b4756197e/src/main/java/org/openrewrite/staticanalysis/AddSerialAnnotationToSerialVersionUID.java#L54-L57

https://github.com/openrewrite/rewrite-migrate-java/blob/1931a6fd3f3999dc20d57b0907d1251447640b07/src/main/java/org/openrewrite/java/migrate/UpgradeJavaVersion.java#L83-L88

Earlier today I'd also added a test to see if we do indeed add the annotation if the field is new: that seems to work: https://github.com/openrewrite/rewrite-static-analysis/commit/5c43d9487304d136f612c3273d5fb09b4756197e

And updating the Java version is pretty much the first thing we do on any Java migration: https://github.com/openrewrite/rewrite-migrate-java/blob/1931a6fd3f3999dc20d57b0907d1251447640b07/src/main/resources/META-INF/rewrite/java-version-17.yml#L28-L30

timtebeek avatar Sep 24 '24 21:09 timtebeek

OK test case:

  1. git clone https://github.com/melloware/quarkus-faces
  2. The whole \src\main\java\org\primefaces\showcase\domain has Serializable POJO's missing both serialversionId and @Serial.
  3. Run mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.migrate.UpgradeToJava17 -Drewrite.exportDatatables=true which is the latest versions of the plugin.

Notice nothing gets touched in the domain package when all of them should have had serialversionID and @Serial added.

melloware avatar Sep 25 '24 12:09 melloware

Thanks for the reproducer steps.. Can't yet look in detail as I'm traveling/PTO for the next week or so, followed by conference. Any help appreciated!

timtebeek avatar Sep 26 '24 16:09 timtebeek

This issue is stale because it has not had any activity for 60 days. Remove question label or comment or this will be closed in two weeks. Issues may be reopened when there is renewed interest.

github-actions[bot] avatar Jul 28 '25 11:07 github-actions[bot]

Not stale!

melloware avatar Jul 28 '25 11:07 melloware