From 1ab8be4c8e3452f8841e8fe39479b243a5053ff8 Mon Sep 17 00:00:00 2001 From: Jente Sondervorst Date: Fri, 13 Feb 2026 21:00:38 +0100 Subject: [PATCH 1/3] Add failing test for superclass method check When a class extends a superclass that already has the method implementation, AddMissingMethodImplementation should not add the method again. Reproduces moderneinc/customer-requests#1862 --- .../AddMissingMethodImplementationTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/org/openrewrite/java/migrate/AddMissingMethodImplementationTest.java b/src/test/java/org/openrewrite/java/migrate/AddMissingMethodImplementationTest.java index eed261e744..2c4b8bb72e 100644 --- a/src/test/java/org/openrewrite/java/migrate/AddMissingMethodImplementationTest.java +++ b/src/test/java/org/openrewrite/java/migrate/AddMissingMethodImplementationTest.java @@ -133,4 +133,23 @@ protected void m1() { ); } + @Issue("https://github.com/moderneinc/customer-requests/issues/1862") + @Test + void skipWhenSuperclassAlreadyHasMethod() { + //language=java + rewriteRun( + java( + """ + interface I1 {} + class SuperClass implements I1 { + public void m1() { + System.out.println("m1 from super"); + } + } + class SubClass extends SuperClass {} + """ + ) + ); + } + } From c51bcee1b242c7d98763adb54978abc9fa3406f9 Mon Sep 17 00:00:00 2001 From: Jente Sondervorst Date: Fri, 13 Feb 2026 21:04:21 +0100 Subject: [PATCH 2/3] Skip adding methods already provided by a superclass AddMissingMethodImplementation now walks up the superclass chain to check if the method is already inherited, avoiding unnecessary duplicate method additions to classes like HikariDataSource subclasses. Fixes moderneinc/customer-requests#1862 --- .../java/migrate/AddMissingMethodImplementation.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/org/openrewrite/java/migrate/AddMissingMethodImplementation.java b/src/main/java/org/openrewrite/java/migrate/AddMissingMethodImplementation.java index ed8ccfa8ca..009812415d 100644 --- a/src/main/java/org/openrewrite/java/migrate/AddMissingMethodImplementation.java +++ b/src/main/java/org/openrewrite/java/migrate/AddMissingMethodImplementation.java @@ -23,6 +23,7 @@ import org.openrewrite.java.MethodMatcher; import org.openrewrite.java.search.UsesType; import org.openrewrite.java.tree.J; +import org.openrewrite.java.tree.JavaType; import org.openrewrite.java.tree.TypeUtils; import static org.openrewrite.java.tree.J.ClassDeclaration.Kind.Type.Interface; @@ -79,6 +80,14 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration cs, Execution .anyMatch(methodDeclaration -> methodMatcher.matches(methodDeclaration, classDecl))) { return classDecl; } + // If a superclass already provides the method, don't add it. + JavaType.FullyQualified supertype = classDecl.getType() != null ? classDecl.getType().getSupertype() : null; + while (supertype != null) { + if (supertype.getMethods().stream().anyMatch(methodMatcher::matches)) { + return classDecl; + } + supertype = supertype.getSupertype(); + } return classDecl.withBody(JavaTemplate.builder(methodTemplateString) .build() From 32185e889885a8fbe7ec5be4cf798dfc3f6986ff Mon Sep 17 00:00:00 2001 From: Jente Sondervorst Date: Fri, 13 Feb 2026 22:55:18 +0100 Subject: [PATCH 3/3] Remove @Issue annotation pointing to private repo --- .../java/migrate/AddMissingMethodImplementationTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/openrewrite/java/migrate/AddMissingMethodImplementationTest.java b/src/test/java/org/openrewrite/java/migrate/AddMissingMethodImplementationTest.java index 2c4b8bb72e..dcc11f09d9 100644 --- a/src/test/java/org/openrewrite/java/migrate/AddMissingMethodImplementationTest.java +++ b/src/test/java/org/openrewrite/java/migrate/AddMissingMethodImplementationTest.java @@ -133,7 +133,6 @@ protected void m1() { ); } - @Issue("https://github.com/moderneinc/customer-requests/issues/1862") @Test void skipWhenSuperclassAlreadyHasMethod() { //language=java