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

ReplaceAnnotation fails when there is a @Nullable parameter in a java record definition #4634

Open
desantisernesto opened this issue Oct 31, 2024 — with Slack · 1 comment
Labels
bug Something isn't working

Comments

Copy link

Hi,

I'm getting the exception below when appling org.openrewrite.java.ReplaceAnnotation to a java record with a @nullable parameter:

Execution failed for task ':rewriteRun'.
> java.lang.RuntimeException: Error while visiting src/main/java/com/desantisernesto/openrewrite/SimpleProject/nullable/RecordNullableParam.java: java.lang.IllegalStateException: Unable to parse annotation from template: 
  @org.checkerframework.checker.nullness.qual.Nullable
  Use JavaTemplate.Builder.doBeforeParseTemplate() to see what stub is being generated and include it in any bug report.

Full log, recipe a record source code in the comments.
Is it a recipe bug? Should I file an issue for it?

Slack Message

@timtebeek timtebeek added the bug Something isn't working label Oct 31, 2024
@timtebeek
Copy link
Contributor

Thanks for logging the issue! Adding the additional details from the Slack thread.

Recipe

type: specs.openrewrite.org/v1beta/recipe
name: com.desantisernesto.ReplaceNullable
displayName: Replace null annotations with the Checker Framework Equivalents
description: Replace null annotations with the Checker Framework Equivalents.
recipeList:
  - org.openrewrite.java.ReplaceAnnotation:
      annotationPatternToReplace: "@jakarta.annotation.Nullable"
      annotationTemplateToInsert: "@org.checkerframework.checker.nullness.qual.Nullable"

record code:

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

public record Person(@Nonnull String lastname, @Nonnull String name, @Nullable Integer age) {
    public Person(String lastname, String name) {
        this(lastname, name, 0);
    }
}

exception:

* What went wrong:
Execution failed for task ':rewriteRun'.
> java.lang.RuntimeException: Error while visiting src/main/java/com/desantisernesto/openrewrite/SimpleProject/nullable/RecordNullableParam.java: java.lang.IllegalStateException: Unable to parse annotation from template: 
  @org.checkerframework.checker.nullness.qual.Nullable
  Use JavaTemplate.Builder.doBeforeParseTemplate() to see what stub is being generated and include it in any bug report.
    org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitAnnotation(JavaTemplateJavaExtension.java:62)
    org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitAnnotation(JavaTemplateJavaExtension.java:55)
    org.openrewrite.java.tree.J$Annotation.acceptJava(J.java:233)
    org.openrewrite.java.tree.J.accept(J.java:59)
    org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
    org.openrewrite.TreeVisitor.visit(TreeVisitor.java:157)
    org.openrewrite.java.JavaTemplate.apply(JavaTemplate.java:115)
    org.openrewrite.java.ReplaceAnnotation$ReplaceAnnotationVisitor.visitAnnotation(ReplaceAnnotation.java:95)
    org.openrewrite.java.ReplaceAnnotation$ReplaceAnnotationVisitor.visitAnnotation(ReplaceAnnotation.java:79)
    org.openrewrite.java.tree.J$Annotation.acceptJava(J.java:233)
    org.openrewrite.java.tree.J.accept(J.java:59)
    org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
    org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:320)
    org.openrewrite.java.JavaVisitor.lambda$visitVariableDeclarations$24(JavaVisitor.java:946)
    org.openrewrite.internal.ListUtils.map(ListUtils.java:177)
    org.openrewrite.java.JavaVisitor.visitVariableDeclarations(JavaVisitor.java:946)

Versions

rewrite version 8.38.1
Gradle 8.10.2
Kotlin:        1.9.24
Groovy:        3.0.22
Ant:           Apache Ant(TM) version 1.10.14 compiled on August 16 2023
Launcher JVM:  17.0.8 (Azul Systems, Inc. 17.0.8+7-LTS)
Daemon JVM:    /Library/Java/JavaVirtualMachines/jdk17.0.8.jdk/Contents/Home (no JDK specified, using current Java home)
OS:            Mac OS X 14.7 aarch64

@timtebeek timtebeek transferred this issue from openrewrite/rewrite-hibernate Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants