Please provide
- Operating system: Any
- SonarLint plugin version: Any, currently using latest (and latest IntelliJ)
- Programming language you’re coding in: Java
- Is connected mode used:
- Connected to SonarCloud or SonarQube (and which version): N/A
And a thorough description of the problem / question:
had a class with a nested builder that originally had no parent class:
public class SomeClass {
public static class Builder {
...
public Builder name(String name) {
return this;
}
...
}
}
I needed to add a parent class, so I used the curiously-recurrring template pattern (Curiously recurring template pattern - Wikipedia):
public class SomeClassBase {
public static class BuilderBase<B extends BuilderBase<B>> {
...
public B name(String name) {
...
return (B) this;
}
...
}
}
public class SomeClass {
public static class Builder extends BuilderBase<Builder> {
...
@Override
public Builder name(String name) {
return super.name(name);
}
...
}
}
Sonar said the “name” method in the subclass could be removed:
Remove this method to simply inherit it.
Overriding methods should do more than simply call the same method in the super class
java:S1185
Unfortunately, that’s really bad advice, because when the method was removed, code already compiled against the original SomeClass no longer worked at runtime, blowing up with a missing-method exception.
The runtime was trying to match the original signature, which was no longer there.
Sonar should warn when its advice could cause a binary incompatibility, or not give advice that can lead to a binary incompatibility, or offer a configuration option to disable advice that could lead to a binary incompatibility.