FP in S2201: Support new switch in java

When using new switch in java, I got a S2201 bug (return of … must be used)

     BigDecimal amount=...;

     String v = switch (param) {
            case xxxx -> "aValue";
            case paymentAmount -> amount.toPlainString();
            case refundAmount -> amount.toPlainString();
            default -> defaultValue();

I got " The return value of “toPlainString” must be used." for both the amount.toPlainString(). (I think it is the same with toString()) this is wrong as the value is used.


Hello @GregoireW

This is indeed a wrong behavior of the rule, I created a ticket to track this issue.

Thanks a lot for this feedback and the clear reproducer, it’s always appreciated!