False negative java:S3012: array copy loop not reported when the copied element is parenthesised

Product/version: SonarQube Community Build 26.9.0.129388 (sonar-java 8.41.0.47177); also 26.7.0.124771 (sonar-java 8.34.0.44906), sonar-scanner 8.1.0.6389

Language: Java

Rule: java:S3012

Issue:

S3012 reports for (int i = 0; i < b.length; i++) this.a[i] = b[i];. The same loop with the element written (b[i]) isn’t reported.

ArrayCopyLoopCheck.isArrayToArrayCopy checks lhs.is(Kind.ARRAY_ACCESS_EXPRESSION) && rhs.is(Kind.ARRAY_ACCESS_EXPRESSION) (ArrayCopyLoopCheck.java:231 at 8.34.0.44906, unchanged on master at e2ff24d5b, 2026-10-08). A parenthesised element is a PARENTHESIZED_EXPRESSION, so the loop isn’t seen as a copy. ExpressionUtils.skipParentheses on both sides would fix it.

Reproducer:

seed/ArrayCopy.java:

public class ArrayCopy {
    private final int[] a;

    public ArrayCopy(int[] b) {
        this.a = new int[b.length];
        for (int i = 0; i < b.length; i++) {
            this.a[i] = b[i];            // Noncompliant: S3012 reported
        }
    }
}

variant/ArrayCopy.java:

public class ArrayCopy {
    private final int[] a;

    public ArrayCopy(int[] b) {
        this.a = new int[b.length];
        for (int i = 0; i < b.length; i++) {
            this.a[i] = (b[i]);          // same copy, no S3012
        }
    }
}

Expected behavior:

S3012 on the loop in variant/ArrayCopy.java, as on the one in seed/ArrayCopy.java: the loop copies the array element by element.

How to reproduce:

# one project per file
sonar-scanner -Dsonar.projectKey=<key> -Dsonar.sources=. \
    -Dsonar.java.binaries=. -Dsonar.scm.disabled=true

Output of the commands above:

### SonarQube Community Build 26.9.0.129388 (sonar-java 8.41.0.47177), server reports 26.9.0.129388, default Sonar way profile  rule: S3012

--- SEED -- expected: reported (seed/)
    java:S1220             line -    Move this file to a named package.
    java:S3012             line 7    Use "Arrays.copyOf", "Arrays.asList", "Collections.addAll" o  <== S3012
    [S3012: 1]

--- VARIANT -- expected: reported; actual: not reported (variant/)
    java:S1220             line -    Move this file to a named package.
    [S3012: 0]