Skip to content

Commit 114a5a2

Browse files
authored
Fix Jackson 2.21+ compatibility for AWT migration recipes (#1007)
Remove `@AllArgsConstructor` from `ReplaceAWTGetPeerMethod` and `ReplaceComSunAWTUtilitiesMethods` and replace the no-arg `@JsonCreator` constructor with an all-args `@JsonCreator` constructor accepting `@Nullable` parameters with defaults. This eliminates the conflicting property-based creators caused by Lombok's `@ConstructorProperties` annotation on the generated all-args constructor. Closes #1003
1 parent 7661bb1 commit 114a5a2

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

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

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

1818
import com.fasterxml.jackson.annotation.JsonCreator;
19-
import lombok.AllArgsConstructor;
2019
import lombok.EqualsAndHashCode;
2120
import lombok.Value;
2221
import org.jspecify.annotations.Nullable;
@@ -29,7 +28,6 @@
2928
import org.openrewrite.java.tree.TypeUtils;
3029
import org.openrewrite.java.tree.TypedTree;
3130

32-
@AllArgsConstructor
3331
@EqualsAndHashCode(callSuper = false)
3432
@Value
3533
public class ReplaceAWTGetPeerMethod extends Recipe {
@@ -47,9 +45,13 @@ public class ReplaceAWTGetPeerMethod extends Recipe {
4745
String lightweightPeerFQCN;
4846

4947
@JsonCreator
50-
public ReplaceAWTGetPeerMethod() {
51-
getPeerMethodPattern = "java.awt.* getPeer()";
52-
lightweightPeerFQCN = "java.awt.peer.LightweightPeer";
48+
public ReplaceAWTGetPeerMethod(
49+
@Nullable String getPeerMethodPattern,
50+
@Nullable String lightweightPeerFQCN) {
51+
this.getPeerMethodPattern = getPeerMethodPattern == null ?
52+
"java.awt.* getPeer()" : getPeerMethodPattern;
53+
this.lightweightPeerFQCN = lightweightPeerFQCN == null ?
54+
"java.awt.peer.LightweightPeer" : lightweightPeerFQCN;
5355
}
5456

5557
String displayName = "Replace AWT `getPeer()` method";

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

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

1818
import com.fasterxml.jackson.annotation.JsonCreator;
19-
import lombok.AllArgsConstructor;
2019
import lombok.EqualsAndHashCode;
2120
import lombok.Value;
21+
import org.jspecify.annotations.Nullable;
2222
import org.openrewrite.ExecutionContext;
2323
import org.openrewrite.Option;
2424
import org.openrewrite.Recipe;
@@ -28,7 +28,6 @@
2828
import org.openrewrite.java.MethodMatcher;
2929
import org.openrewrite.java.tree.J;
3030

31-
@AllArgsConstructor
3231
@EqualsAndHashCode(callSuper = false)
3332
@Value
3433
public class ReplaceComSunAWTUtilitiesMethods extends Recipe {
@@ -77,14 +76,28 @@ public class ReplaceComSunAWTUtilitiesMethods extends Recipe {
7776
String setComponentMixingCutoutShapePattern;
7877

7978
@JsonCreator
80-
public ReplaceComSunAWTUtilitiesMethods() {
81-
getAWTIsWindowsTranslucencyPattern = "com.sun.awt.AWTUtilities isTranslucencySupported(com.sun.awt.AWTUtilities.Translucency)";
82-
getWindowOpacityPattern = "com.sun.awt.AWTUtilities getWindowOpacity(java.awt.Window)";
83-
getWindowShapePattern = "com.sun.awt.AWTUtilities getWindowShape(java.awt.Window)";
84-
isWindowOpaquePattern = "com.sun.awt.AWTUtilities isWindowOpaque(java.awt.Window)";
85-
isTranslucencyCapablePattern = "com.sun.awt.AWTUtilities isTranslucencyCapable(java.awt.GraphicsConfiguration)";
86-
setComponentMixingCutoutShapePattern = "com.sun.awt.AWTUtilities setComponentMixingCutoutShape(java.awt.Component,java.awt.Shape)";
87-
setWindowOpacityPattern = "com.sun.awt.AWTUtilities setWindowOpacity(java.awt.Window, float)";
79+
public ReplaceComSunAWTUtilitiesMethods(
80+
@Nullable String getAWTIsWindowsTranslucencyPattern,
81+
@Nullable String isWindowOpaquePattern,
82+
@Nullable String isTranslucencyCapablePattern,
83+
@Nullable String setWindowOpacityPattern,
84+
@Nullable String getWindowOpacityPattern,
85+
@Nullable String getWindowShapePattern,
86+
@Nullable String setComponentMixingCutoutShapePattern) {
87+
this.getAWTIsWindowsTranslucencyPattern = getAWTIsWindowsTranslucencyPattern == null ?
88+
"com.sun.awt.AWTUtilities isTranslucencySupported(com.sun.awt.AWTUtilities.Translucency)" : getAWTIsWindowsTranslucencyPattern;
89+
this.isWindowOpaquePattern = isWindowOpaquePattern == null ?
90+
"com.sun.awt.AWTUtilities isWindowOpaque(java.awt.Window)" : isWindowOpaquePattern;
91+
this.isTranslucencyCapablePattern = isTranslucencyCapablePattern == null ?
92+
"com.sun.awt.AWTUtilities isTranslucencyCapable(java.awt.GraphicsConfiguration)" : isTranslucencyCapablePattern;
93+
this.setWindowOpacityPattern = setWindowOpacityPattern == null ?
94+
"com.sun.awt.AWTUtilities setWindowOpacity(java.awt.Window, float)" : setWindowOpacityPattern;
95+
this.getWindowOpacityPattern = getWindowOpacityPattern == null ?
96+
"com.sun.awt.AWTUtilities getWindowOpacity(java.awt.Window)" : getWindowOpacityPattern;
97+
this.getWindowShapePattern = getWindowShapePattern == null ?
98+
"com.sun.awt.AWTUtilities getWindowShape(java.awt.Window)" : getWindowShapePattern;
99+
this.setComponentMixingCutoutShapePattern = setComponentMixingCutoutShapePattern == null ?
100+
"com.sun.awt.AWTUtilities setComponentMixingCutoutShape(java.awt.Component,java.awt.Shape)" : setComponentMixingCutoutShapePattern;
88101
}
89102

90103
String displayName = "Replace `com.sun.awt.AWTUtilities` static method invocations";

0 commit comments

Comments
 (0)