# java:S1905 java redundant casts

**URL:** <https://community.sonarsource.com/t/java-s1905-java-redundant-casts/43350>\
**Category:** SonarQube Cloud\
**Tags:** java\
**Created:** [May 17, 2021, 8:48pm UTC](https://community.sonarsource.com/t/java-s1905-java-redundant-casts/43350 "2021-05-17T20:48:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![reitzmichnicht](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/reitzmichnicht/32/288_2.png) [@reitzmichnicht](https://community.sonarsource.com/u/reitzmichnicht)\
**Post date:** [May 17, 2021, 8:48pm UTC](https://community.sonarsource.com/t/java-s1905-java-redundant-casts/43350/1 "2021-05-17T20:48:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/michael/32/43_2.png) [@Michael](https://community.sonarsource.com/u/Michael)\
**Post date:** [May 25, 2021, 3:00pm UTC](https://community.sonarsource.com/t/java-s1905-java-redundant-casts/43350/3 "2021-05-25T15:00:32Z")

</div>

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](https://jira.sonarsource.com/browse/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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [June 1, 2021, 3:01pm UTC](https://community.sonarsource.com/t/java-s1905-java-redundant-casts/43350/5 "2021-06-01T15:01:24Z")

</div>

Closed on June 1, 2021, 3:01pm UTC

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