S2629 False Positive on Java record getter

Windows 10, Eclipse 2023-03, SonarLint, Java 17

Problem: false positive S2629 on Record getters.

Code Example:

public record r(String name) { }
log.debug("The name is: {}", r.name());

r.name() is flagged for S2629, but it is essentially a getter for the record.

Hello @jeff-tyl,

Thanks for your message. Indeed, this code feels like a valid one, so I created a ticket to fix it:


However, there is still a corner case, if the getter is overridden and does some expensive computations. Anyway, I don’t feel like that is a common practice.


1 Like