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

org.openrewrite.java.migrate.UpgradeToJava17 #373

Open
nddipiazza-ebay opened this issue Oct 15, 2024 · 4 comments
Open

org.openrewrite.java.migrate.UpgradeToJava17 #373

nddipiazza-ebay opened this issue Oct 15, 2024 · 4 comments
Labels
bug Something isn't working question Further information is requested

Comments

@nddipiazza-ebay
Copy link

nddipiazza-ebay commented Oct 15, 2024

Issue with org.openrewrite.staticanalysis.AddSerialAnnotationToSerialVersionUID

As a result of addressing
openrewrite/rewrite-migrate-java#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
@nddipiazza-ebay nddipiazza-ebay added the bug Something isn't working label Oct 15, 2024
@melloware
Copy link

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

@timtebeek timtebeek transferred this issue from openrewrite/rewrite-migrate-java Oct 16, 2024
@timtebeek
Copy link
Contributor

Would also help to know what version you're using, and indeed ideally as a failing unit test, as per this example.

@Test
void addSerialAnnotation() {
rewriteRun(
//language=java
java(
"""
import java.io.Serializable;
class Example implements Serializable {
private static final long serialVersionUID = 1L;
}
""",
"""
import java.io.Serial;
import java.io.Serializable;
class Example implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
}
"""
)
);
}

Adding the annotation is directly above adding the annotation, so I wouldn't expect any issue.

if (isPrivateStaticFinalLongSerialVersionUID(vd) &&
FindAnnotations.find(vd, "@java.io.Serial").isEmpty()) {
maybeAddImport("java.io.Serial");
return JavaTemplate.builder("@Serial")
.imports("java.io.Serial")
.build()
.apply(getCursor(), vd.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName)));
}

@timtebeek timtebeek added the question Further information is requested label Oct 16, 2024
@nddipiazza-ebay
Copy link
Author

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
Status: No status
Development

No branches or pull requests

3 participants