Addition to existing FP in Jira - rule S1120, JIRA ticket SONARJAVA-4401

Causing dozens of FPs for us just in one PR.

  • What language is this for? Java

See [SONARJAVA-4401] - Jira

Java 17 switches cause FP not just with -> methodCall(); syntax, but also when using switch blocks. e.g.

public class Main
    enum Kind { REGEXP, TAGS, REST }
    public static void main(String[] args) {
        Kind kind = Kind.REGEXP;
        switch(kind) {
            case REGEXP -> {
              yield ofNullable(portfolio.getSelectionExpression()).ifPresent(view::setRegexp); // FP
            case TAGS -> ofNullable(portfolio.getSelectionExpression()).ifPresent(tags -> view.setTagsAssociation(getTags(portfolio))); // FP
            case REST -> view.setDef(true); // FP
            default -> {

This may be a combination of [SONARJAVA-4401] - Jira and [SONARJAVA-1186] - Jira

Hello Bruce,

Thanks for providing this feedback and the reproducer. Indeed, this seems to be an issue in many variations. I’ve added the information you provided to the ticket to make sure we cover all cases when we fix this problem.

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