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
- 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;
}
}
- 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.
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.
Describe the bug
If a
@Beanannotation is applied to an@Overridemethod in a class that implements an interface requiring said implemented method to be apublicmethod, the STS4 linter will indicate a false positive.To Reproduce
@Beancan be applied to thegetValidator(), which is a method to be implemented for the interfaceWebMvcConfigurer. However, the side effect is the@Beanwould hint that thepublicaccess modifier must not need to be present, which conflicts with the@Overridetag.The class
WebMvcConfigurercomes 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
LocalValidatorFactoryBeanclass. 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.