Redundant casts should not be used (S1905) - vavr Try.of(...).getOrElseThrow(...)

Current sonarcloud.

For code:

Try.of(() -> ...)
   .getOrElseThrow((Function<Throwable, IOException>) IOException::new);

sonar report issue: Redundant casts should not be used (S1905)

But we have two declaration for getOrElseThrow:
In io.vavr.control.Try interface

default <X extends Throwable> T getOrElseThrow(Function<? super Throwable, X> exceptionProvider) throws X

and in io.vavr.Value interface

default <X extends Throwable> T getOrElseThrow(Supplier<X> supplier) throws X

Try extends Value

So casts in need in this case.

Hello @slawekjaranowski,

Thanks for the feedback, I agree that we have a problem here.Ticket created (SONARJAVA-3468).

For the record, I created a simplified example without generics on the ticket.

You can resolve the issue as false positive in the meantime, this is a quite tricky and specific issue, I expect it to not be that frequent.

Best,
Quentin

1 Like