Skip to content

Commit c421ab1

Browse files
authored
Fix Jackson 2.21+ compatibility for JREThrowableFinalMethods (#1010)
Remove @requiredargsconstructor which generates @ConstructorProperties on the all-args constructor, conflicting with the no-arg @JsonCreator. Change @JsonCreator to accept nullable parameters with defaults, matching the pattern from #1007. This resolves the InvalidDefinitionException: Conflicting property-based creators reported in issue #1003.
1 parent 9826a90 commit c421ab1

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/main/java/org/openrewrite/java/migrate/JREThrowableFinalMethods.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
package org.openrewrite.java.migrate;
1717

1818
import com.fasterxml.jackson.annotation.JsonCreator;
19-
import lombok.AccessLevel;
2019
import lombok.EqualsAndHashCode;
2120
import lombok.Getter;
22-
import lombok.RequiredArgsConstructor;
21+
import org.jspecify.annotations.Nullable;
2322
import org.openrewrite.ExecutionContext;
2423
import org.openrewrite.Preconditions;
2524
import org.openrewrite.Recipe;
@@ -33,16 +32,19 @@
3332
import org.openrewrite.java.tree.TypeUtils;
3433

3534
@EqualsAndHashCode(callSuper = false)
36-
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
3735
public class JREThrowableFinalMethods extends Recipe {
3836

3937
private final String methodPatternAddSuppressed;
4038
private final String methodPatternGetSuppressed;
4139

4240
@JsonCreator
43-
public JREThrowableFinalMethods() {
44-
this.methodPatternAddSuppressed = "*..* addSuppressed(Throwable)";
45-
this.methodPatternGetSuppressed = "*..* getSuppressed()";
41+
public JREThrowableFinalMethods(
42+
@Nullable String methodPatternAddSuppressed,
43+
@Nullable String methodPatternGetSuppressed) {
44+
this.methodPatternAddSuppressed = methodPatternAddSuppressed == null ?
45+
"*..* addSuppressed(Throwable)" : methodPatternAddSuppressed;
46+
this.methodPatternGetSuppressed = methodPatternGetSuppressed == null ?
47+
"*..* getSuppressed()" : methodPatternGetSuppressed;
4648
}
4749

4850
@Getter

src/test/java/org/openrewrite/java/migrate/JREThrowableFinalMethodsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void methodUsingException(ThrowableWithIllegalOverrrides t1) {
9191
void shouldRenameOnJava6() {
9292
//language=java
9393
rewriteRun(
94-
spec -> spec.recipe(new JREThrowableFinalMethods()),
94+
spec -> spec.recipe(new JREThrowableFinalMethods(null, null)),
9595
java(
9696
"""
9797
class ClassUsingThrowable {
@@ -118,7 +118,7 @@ void methodUsingRenamedMethodsAlready(Throwable t1) {
118118
void shouldNotRenameOnJava7() {
119119
//language=java
120120
rewriteRun(
121-
spec -> spec.recipe(new JREThrowableFinalMethods()),
121+
spec -> spec.recipe(new JREThrowableFinalMethods(null, null)),
122122
java(
123123
"""
124124
class ClassUsingThrowable {

0 commit comments

Comments
 (0)