Skip to content

DefaultValue annotation on a record seems to fail #714

@tubbynl

Description

@tubbynl

i recently started using the @DefaultValue annotation to add sensible defaults on config properties in combination with java records. This works (as-in, compiles, tests, and runs as expected). Only when i run OpenRewrite it fails seemingly on parsing this code.

How are you running OpenRewrite?

Maven

<plugin>
                <groupId>org.openrewrite.maven</groupId>
                <artifactId>rewrite-maven-plugin</artifactId>
                <version>6.9.0</version>
                <configuration>
                    <activeRecipes>
                        <recipe>org.openrewrite.java.migrate.UpgradeToJava21</recipe>
                        <recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3</recipe>
                        <recipe>org.openrewrite.java.testing.junit5.JUnit5BestPractices</recipe>
                        <recipe>org.openrewrite.java.spring.boot3.SpringBoot33BestPractices</recipe>
                    </activeRecipes>
                    <failOnDryRunResults>true</failOnDryRunResults>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.openrewrite.recipe</groupId>
                        <artifactId>rewrite-spring</artifactId>
                        <version>6.7.0</version>
                    </dependency>
                </dependencies>
            </plugin>

What is the smallest, simplest way to reproduce the problem?

add below Java file to a spring-boot 3.4ish project and try to run above recipes

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.DefaultValue;

@ConfigurationProperties("nl.tubby")
record TestTubbyProperties(
         @DefaultValue("https://www.tubby.nl") String url
) {
}

What did you expect to see?

to handle / parse this file correctly (and rewrite where applicable)

What did you see instead?

LST contains erroneous nodes

  StringurlltValue("https://www.tubby.nl") String url

java.lang.IllegalStateException: LST contains erroneous nodes

  StringurlltValue("https://www.tubby.nl") String url

Are you interested in contributing a fix to OpenRewrite?

willing to help; see test

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingquestionFurther information is requested

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions