java:S9395 clashes with java:S1905

Simple reproducer:

void main() {
    doSomething(10);
}

void doSomething(final int i) {
    this.doSomethingElse(i);
}

void doSomethingElse(final float f) {
    IO.println(f);
}

This results in a single finding when scanned:

(6, 25) Explicitly cast this "int" to "float" to document potential precision loss. [java:S9395]

So I follow this advice and insert an explicit cast:

void main() {
    doSomething(10);
}

void doSomething(final int i) {
    this.doSomethingElse((float) i); // Explicit cast inserted
}

void doSomethingElse(final float f) {
    IO.println(f);
}

But upon rescanning, I get a different finding:

(6, 25) Remove this unnecessary cast to "float". [java:S1905]

So I’m kind of stuck :sweat_smile:
These two rules seem to clash here.

That seems like undesired behavior. :slight_smile:

Hi, thanks for reporting this issue!

I have opened a ticket to detect casts that are probably there for documentation in java:S1905, this issue should be fixed for the next release of SonarJava.