Skip to content

[validation] False positive for [JAVA_PUBLIC_BEAN_METHOD] lint warning #1911

Closed

Description

@tommai78101

Describe the bug
If a @Bean annotation is applied to an @Override method in a class that implements an interface requiring said implemented method to be a public method, the STS4 linter will indicate a false positive.

To Reproduce

  1. Copy the following code a Spring MVC or Spring Boot project of your choice:
package my.pkg.namespace;

import java.nio.charset.StandardCharsets;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class MessageValidatorConfiguration implements WebMvcConfigurer {

	@Bean
	MessageSource messageSource ( ) {
		ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
		messageSource.setBasename("messages");
		messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name());
		return messageSource;
	}

	// WARNING shows here by the "public" accessor keyword.
	@Bean
	@Override
	public LocalValidatorFactoryBean getValidator ( ) {
		LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
		bean.setValidationMessageSource(messageSource());
		return bean;
	}
}
  1. As indicated in the comment above, the @Bean can be applied to the getValidator(), which is a method to be implemented for the interface WebMvcConfigurer. However, the side effect is the @Bean would hint that the public access modifier must not need to be present, which conflicts with the @Override tag.
Image

The class WebMvcConfigurer comes from this source code file from the Spring Web MVC project:

https://github.com/spring-projects/spring-framework/blob/main/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurer.java

Is this a false positive? Please let me know. Thank you in advance.

We do use this wacky set up where we can autowire an overridden LocalValidatorFactoryBean class. There is no indication that we're doing this the right or wrong way, but it's being used for a couple of years in production for us.

Activity

  1. BoykoAlex commented on Jun 9, 2026

    @BoykoAlex
    Contributor

    Yes, we shouldn't be flagging the overriden methods

  2. added this to the 5.3.0.RELEASE milestone on Jun 9, 2026
  3. added
    for: eclipse
    for: vscode
    on Jun 9, 2026
  4. goutamadwant commented on Jun 17, 2026

    @goutamadwant
    Contributor

    @martinlippert Opened #1915 with a small fix for this.

    This change keeps the existing override check and also checks inherited superclass/interface methods.. so public @bean methods like WebMvcConfigurer#getValidator() are not reported as JAVA_PUBLIC_BEAN_METHOD.

  5. added a commit that references this issue on Jun 18, 2026
    2cf06f1
  6. added a commit that references this issue on Jun 18, 2026
    75ea892
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: eclipsefor: vscodetheme: validationtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions