Sonar Lint complaining on factory method to parametrize generic type - Spring Boot

Viewed 222

I have this generic interface to validate the request and throw custom exception. Then I have an abstract class which implements this interface, which will have the common validation shared across the request and the actual implementation class for each request which extends this abstract class. I have a factory method which returns a bean based on the request. When I run sonar lint, it is complaining on return type of the getValidator(Action action), the message is "Provide the parameterized type for this generic" . It is a major code smell and I want to get rid of it. Is there a better way to do this? Or should I just ignore it?

//Interface

@FunctionalInterface
public interface CustomValidation<T> {
    
    /**
     * Validate method to throw custom exception when bean validation fails
     *
     * @param t
     */
    void validate(String clientId, T t);
}

//Abstract Class

public abstract class AbstractCustomValidation<T> implements CustomValidation<T> {
  //do something
}

//Factory 

@Component
public class CustomValidatorFactory {
    
    @Autowired
    @Qualifier("a")
    private CustomValidation<A> a;
    
    @Autowired
    @Qualifier("b")
    private CustomValidation<B> b;
    
    @Autowired
    @Qualifier("c")
    private CustomValidation<C> c;
    
    
    @Autowired
    @Qualifier("d")
    private CustomValidation<D> d;
    
    public CustomValidation getValidator(Action action) {
        switch (action) {
            case A:
                return a;
            case B:
                return b;
            case C:
                return c;
            case D:
                return d;
            default:
                return null;
        }
    }
}
0 Answers
Related