False negative java:S1068: an unused private field declared in an enum is not reported

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:S1068

Issue:

S1068 reports private int unused = 1; in a class. The same field in an enum isn’t reported, though nothing reads it there either.

UnusedPrivateFieldCheck.nodesToVisit subscribes to Tree.Kind.CLASS and Tree.Kind.RECORD (UnusedPrivateFieldCheck.java:101 at 8.34.0.44906, line 88 on master at e2ff24d5b, 2026-10-08), so enum bodies are never collected. SONARJAVA-6425 (t/182812, 2026-05; fixed 2026-06-02 in 7f660b62e, released in 8.31.0) added records for the same reason, but Tree.Kind.ENUM is still missing.

Reproducer:

seed/Holder.java:

public class Holder {
    private int unused = 1;          // Noncompliant: S1068 reported
}

variant/Holder.java:

public enum Holder {
    ONE;
    private int unused = 1;          // same field, no S1068
}

Expected behavior:

S1068 on the field in variant/Holder.java, as on the one in seed/Holder.java: nothing reads it.

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: S1068

--- SEED -- expected: reported (seed/)
    java:S1220             line -    Move this file to a named package.
    java:S1068             line 2    Remove this unused "unused" private field.  <== S1068
    [S1068: 1]

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