False negative java:S1488 — immediately-returned local variable not detected when declaration split

Product: SonarQube Community Build 26.7.0.124771

Type: false negative.

Explanation (expected vs actual): S1488 flags a local declared only to be immediately returned. Splitting the declaration-with-initializer into a declaration plus a single immediate assignment is behaviour-identical, the temporary is still write-once and returned on the next statement, and the rule’s prescribed fix (return in.read();) still applies verbatim — but the checker only matches declaration-with-initializer immediately followed by return, so the split form goes silent.

class ReturnTemp {
    int read(java.io.InputStream in) throws java.io.IOException {
        int c = in.read();   // Noncompliant — S1488 reported (baseline)
        return c;
    }
}

Variant — not reported (same valueless temporary):

class ReturnTemp {
    int read(java.io.InputStream in) throws java.io.IOException {
        int c;
        c = in.read();       // same temp, now split; no S1488
        return c;
    }
}

Hello @MarkLee131,

Thank you for your detailed report and code examples. Yes, Java rule S1488 currently only flags cases where a local variable is declared and initialized in a single statement, immediately followed by a return or throw. When the declaration and assignment are split into two statements the rule does not trigger, even if the assignment is immediately before the return.

There is currently no configuration or workaround to extend S1488 to cover the split-declaration pattern. I have flagged this for the relevant dev team to consider this improvement for the rule.

Best regards,

Stevan