Skip to content

Skip adding methods already provided by a superclass#983

Merged
timtebeek merged 3 commits intomainfrom
superclass-method-check
Feb 14, 2026
Merged

Skip adding methods already provided by a superclass#983
timtebeek merged 3 commits intomainfrom
superclass-method-check

Conversation

@Jenson3210
Copy link
Contributor

@Jenson3210 Jenson3210 commented Feb 13, 2026

Summary

  • AddMissingMethodImplementation now checks the superclass hierarchy before adding a method
  • Prevents duplicate method stubs when a superclass already provides the implementation

Problem

When running the Spring Boot 4 migration recipe, isWrapperFor, unwrap, and getParentLogger methods were being added to classes that extend superclasses (e.g., HikariDataSource, SnowflakeBasicDataSource) which already provide these methods. The recipe only checked the class's own body for existing methods, not the inherited ones.

Solution

Walk up the getSupertype() chain in AddMissingMethodImplementation and check if any superclass already has a matching method via getMethods(). If so, skip adding the method.

Test plan

  • Existing tests pass

  • New test added: skipWhenSuperclassAlreadyHasMethod — verifies that a subclass extending a superclass with the method is left unchanged

  • Fixes moderneinc/customer-requests#1862

When a class extends a superclass that already has the method
implementation, AddMissingMethodImplementation should not add
the method again.

Reproduces moderneinc/customer-requests#1862
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
@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Feb 14, 2026
@timtebeek timtebeek merged commit 7a5a1b0 into main Feb 14, 2026
1 check passed
@timtebeek timtebeek deleted the superclass-method-check branch February 14, 2026 14:13
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants

Comments