Sonar version
- Data Center Edition
- v2025.2 (105476)
Language
- Java
Objected code
private Instant truncateToEnsureConsistentPrecision(Instant timestamp) {
// Some sub-systems use nanosecond precision, others microsecond precision;
// without truncating, identical timestamp can look slightly different and fail comparisons.
return timestamp.truncatedTo(ChronoUnit.MICROS);
}
Check result
“This block of commented-out lines of code should be removed.
Sections of code should not be commented out [java:S125]”
Why false negative?
The comment does not contain any code, only a plain English explanation why the method is necessary, and designed this way.
Pre-Analysis
Sonar reacts to the presence of a semicolon at the end of the first comment line. Removing the semicolon or replacing it with a different character, such as a hyphen, makes it ignore the code.