-
Notifications
You must be signed in to change notification settings - Fork 109
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
What version of OpenRewrite are you using?
- org.openrewrite:rewrite-core:8.59.1
- org.openrewrite.recipe:rewrite-migrate-java:3.14.1
What is the smallest, simplest way to reproduce the problem?
Lombok's value classes has is* style getters for boolean fields. Java records do not. The LombokValueToRecord does not take this into account, potentially creating non-compiling code.
@Test
public void lombokValueWithBoolean() {
rewriteRun(
spec -> spec.recipe(new LombokValueToRecord(false)),
java(
"""
package com.helloworld;
import lombok.Value;
@Value
public class Foo {
boolean bar;
}
""",
s -> s.markers(new JavaVersion(randomId(), "", "", "21", "21"))),
java(
"""
package com.helloworld;
public class Baz {
public void baz(Foo foo) {
foo.isBar();
}
}
"""));
}org.opentest4j.AssertionFailedError: [Expected recipe to complete in 0 cycles, but took at least one more cycle. Between the last two executed cycles there were changes to "com/helloworld/Foo.java"]
expected:
"package com.helloworld;
import lombok.Value;
@Value
public class Foo {
boolean bar;
}"
but was:
"package com.helloworld;
public record Foo(
boolean bar) {
}"
at org.openrewrite.test.LargeSourceSetCheckingExpectedCycles.afterCycle(LargeSourceSetCheckingExpectedCycles.java:97)
at org.openrewrite.RecipeScheduler.runRecipeCycles(RecipeScheduler.java:95)
at org.openrewrite.RecipeScheduler.scheduleRun(RecipeScheduler.java:41)
at org.openrewrite.Recipe.run(Recipe.java:441)
at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:377)
at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:130)
Some options would include:
- Bail on any boolean field being present (this is the approach the test above takes)
- Create the ´is*´ getters in the output record as wrappers around the record getter
- Detect if fields are accessed through
is*style getters. It the class/record is part of an API, this would change the API definition, so not sure if this is a great option.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
Done