Skip to content

Do not flag overridden bean methods - #1915

Merged
BoykoAlex merged 1 commit into
spring-projects:mainfrom
goutamadwant:GH-1911
Jun 18, 2026
Merged

BoykoAlex merged 1 commit into
spring-projects:mainfrom
goutamadwant:GH-1911

Conversation

@goutamadwant

Copy link
Copy Markdown
Contributor

Fixes gh-1911

This avoids reporting JAVA_PUBLIC_BEAN_METHOD when a public @Bean method overrides a method inherited from a superclass or implemented interface.

The reconciler keeps the existing override check and also walks the declaring type hierarchy with ASTUtils.getHierarchyTypesBreadthFirstIterator(...), using JDT's public IMethodBinding.overrides(...) against inherited methods. This covers cases such as WebMvcConfigurer#getValidator().

Tests:

  • ./mvnw -pl spring-boot-language-server -am -Dtest=SpringValidationBeanMethodNotPublicTest,BeanMethodNotPublicReconcilerTest -Dsurefire.failIfNoSpecifiedTests=false test


public static final boolean isNotOverridingPublicMethod(IMethodBinding methodBinding) {
return !isOverriding(methodBinding) && (methodBinding.getModifiers() & Modifier.PUBLIC) != 0;
return methodBinding != null && !isOverriding(methodBinding) && !overridesInheritedMethod(methodBinding)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd replace the body of isOverriding with the body of overridesInheritedMethod. The isOverriding does not work when the method being overriden is located in the JAR rather than in a java source file.
I'd make the method return:

return methodBinding != null && (methodBinding.getModifiers() & Modifier.PUBLIC) != 0 && !isOverriding(methodBinding)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review @BoykoAlex updated this as suggested.

@BoykoAlex
BoykoAlex merged commit 75ea892 into spring-projects:main Jun 18, 2026
1 check passed
@BoykoAlex

Copy link
Copy Markdown
Contributor

Thanks very much for the fix!-)

@martinlippert martinlippert added this to the 5.3.0.RELEASE milestone Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[validation] False positive for [JAVA_PUBLIC_BEAN_METHOD] lint warning

3 participants