In my project we have a class for every Identity which implements a common interface. Whenever we try to use a specific Identity class, java:S3242
complains that we could be accepting a LongIdentity instead. This is clearly wrong, as we don’t want anyone passing in any random id, that would defeat the purpose of having these wrapper classes. For these, it makes most sense to always accept the most specific Identity type you can get away with, not the most generic.
public interface LongIdentity {
Long value();
}
public record UserId(String value) implements LongIdentity
public UserId getUser(UserId userId) {
return crudRepo.findById(userId.value());
}
SonarQube is good at telling if you could use a more generic interface for a Collection, but it is not equipped to tell if our code really needs a UserId or not. I’d like to avoid annotating thousands of methods to suppress this warning, and I’d like to keep the warning enabled in general.
Is there some way we can globally tell SonarQube not to report this issue for anything implementing our base interface?