S1144 mentions a used method as unused

Make sure to read this post before raising a thread here:

Then tell us:

  • What language is this for? Java 26
  • Which rule? S1144
  • Why do you believe it’s a false-positive/false-negative? see code snippet
  • Are you using
    • SonarQube Server / Community Build - v26.6.0.123539
    • SonarQube for IDE - IntelliJ IDEA 2026.2.3, Sonar Plugin 13.0.0.85671
      • in connected mode with SonarQube Server / Community Build or SonarQube Cloud? - SonarQube Community Build
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
package sonarrepro;

import java.util.List;

/**
 * False positive: a private method of a nested type which the enclosing class uses only through a method reference
 * inside a {@code finally} block is reported as unused.
 * <p>
 * Expected: no issue for java:S1144. Actual: "Remove this unused private "discard" method." on
 * {@code Output.discard}. No issue is raised if the method reference is moved out of the {@code finally} block, or
 * if it is replaced by the lambda {@code output -> output.discard()}. A nested class behaves like a nested record.
 */
public class FinallyMethodReferenceNested {

    private final List<Output> outputs = List.of(new Output("a"), new Output("b"));

    public void close() {
        try {
            System.out.println("closing");
        } finally {
            outputs.forEach(Output::discard);
        }
    }

    private record Output(String name) {

        private void discard() {
            System.out.println("discard " + name);
        }
    }
}

Hello @idlira,

Thank you for your report. I was able to reproduce the reported false positive and have created a ticket for us to fix it.

Best regards,
Aurélien