If I implement an interface method or override a method, that returns a value, rule S3516 should not hit due to “always the same value”.
Consider this code:
public interface I
{
/**
* @return result object or null, if nothing produced.
*/
Object doSomethingAndReturnResultObject();
}
public class C implements I
{
@Override
public Object doSomethingAndReturnResultObject()
{
// No result object in this implementation.
if ( exitCondition )
return null; // FP
doSomethingProductive();
return null; // FP
}
}
I see, that in most cases always the same value is a good chance for wrong code. But as you can see, if an interface is implemented, this is not always true.
Maybe there’s no solution, but to place NOSONARs or to disable the rule. But these are my 5 cents.