rewrite-static-analysis
rewrite-static-analysis copied to clipboard
Add @Serial annotation to serialVersionUID not working
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?
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
OK test case:
git clonehttps://github.com/melloware/quarkus-faces- The whole
\src\main\java\org\primefaces\showcase\domainhas Serializable POJO's missing both serialversionId and@Serial. - 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=truewhich 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.
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!
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.
Not stale!