java:S1130 reports on overriden method when super method outside of source control has superfluous Exception declarations
- What language is this for?
Java - Which rule?
Java:S1130 - Why do you believe it’s a false-positive/false-negative?
- Are you using
- SonarQube Cloud?
- SonarQube Server / Community Build - which version?
- SonarQube for IDE - which IDE/version?
- in connected mode with SonarQube Server / Community Build or SonarQube Cloud?
SonarLint for IntelliJ 10.12.0.79769
- in connected mode with SonarQube Server / Community Build or SonarQube Cloud?
- How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
When extending a class from a library, it is (at least in my view) good practice to keep the throws declarations equal to those of the super method. However, when the super method has superfluous throws declarations (like StdDeserializer.deserialize from Jackson), this leads to java:S1130 reporting:
public class SanitizedStringDeserializer extends StdDeserializer<String> {
public SanitizedStringDeserializer() {
super(String.class);
}
@Override
public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
var originalText = jsonParser.getText();
var sanitized = stripHtml(originalText);
return trimToEmpty(sanitized);
}
}
Removing the superfluous throws declaration of JacksonException (which directly extends IOException) is acceptable for the compiler, but in my opinion not desirable because the visible signature of the method is different from that of the super method. When the super method is outside of source control (in this case a library) in my opinion this rule should not trigger.
I’ll admit I’m not 100% sure whether this should be a false positive or it should be in Discussions. Please move this report if it’s better suited else where.