java:S1905 java redundant casts

I’m using Sonarqube 8.9 LTS and have a false positive in my code;
Given:

  public void onEntryFrom(T trigger, final Runnable entryAction) {
    onEntryFrom(trigger, (BiConsumer<Transition<S, T>, C>) (t, c) -> entryAction.run());
  }

  public void onEntryFrom(T trigger, final BiConsumer<Transition<S, T>, C> entryAction) {
  }

  public void onEntryFrom(T trigger, final BiFunction<Transition<S, T>, C, T> entryAction) {
  }

Sonarqube complains about the cast here (BiConsumer<Transition<S, T>, C>) (t, c) → entryAction.run()

But without the cast the compiler complains:

  both method onEntryFrom(T,BiConsumer<Transition<S,T>,C>) and method onEntryFrom(T,BiFunction<Transition<S,T>,C,T>) match
  where T,S,C are type-variables:
    T extends Object declared in class StateConfiguration
    S extends Object declared in class StateConfiguration
    C extends Object declared in class StateConfiguration

Kind regards,
Michael

Hey @reitzmichnicht ,

Thanks for reporting this!

This is indeed a FP, which was caused by some approximations in the implementation of the rules. We are precisely working on improving this rule at the moment (SONARJAVA-3794), and I confirm I can not reproduce the issue anymore with our latest fix!

The fix will be part of our next release, which will be available with SQ 9.0 and SonarCloud.

Cheers,
Michael

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.