java:S4165 Should not judge about method implementation

The Java rule S4165 complains about a variable assignment to be redundant, which it technically is. But it’s the wrong place to tell. See the following code.

public static String foo( String s )
{
    // We may want to do something really smart with this String before returning.
    return s;
}
String bar = "bar";
bar = MyClass.foo( bar ); // FP

At the marked line Sonar says, that the assignment is redundant. Yes, it is. But who are we to forsee the implementation of the foo() method? It may change. Do I have to add a NOSONAR tag to any location, where a library decides to change a method’s implementation? Ot should I even change my implementation and remember to change it back when the lib’s changelog tells me, that this method actually does something to the return value again? Not a good idea.

I do agree, that this may be woth to be notified for other cases. But for this case it is definitely FP.

Used products: Java, SonarCube and Lint.
Qube 8.3, soon 9.4.
Lint 7.4.0.