False Positive java:S1118 - Lombok already handles this

Must-share information (formatted with Markdown):

  • Version: SonarQube Enterprise Edition v2025.1.2 (108896)
  • Location: On-premises server
  • Chief complaint: Report a false positive for Java:S1118
  • Desired resolution: Sonar recognizes Lombok’s annotation for private constructor to hide the implicit public one.

I utilize Lombok with my classes to remove the need for setting up boilerplates manually. For utility classes, they are always annotated with @NoArgsConstructor(access = AccessLevel.PRIVATE) and my code keeps getting flagged by Sonar with “Add a private constructor to hide the implicit public one.”

This should not raise the java:S1118 error.

package my.project;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;


@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class Thing {

    public static boolean returnThis() {
        return true;
    }
}

This is the class in my simple MCVE repo: sonar-private-constructor-issue/src/main/java/com/example/utils/StringUtils.java at main · robert-plagge-usps/sonar-private-constructor-issue · GitHub

This was moved from Sonar Cloud category… I eventually found the correct category (Rules and Languages), and then moved this post here.

Following up on this since it has been almost two weeks now…

Can someone please shed some light on this false positive?

I’d appreciate it :slight_smile:

Hi,

It looks like this is fixed in the latest versions. Can you upgrade?

 
Thx,
Ann

Ah, so I might have the outdated version.

I’ll ask the automation build tool team at work to see when they plan on updating the version, and then try again.

I’ll keep this thread posted.

Thanks for the update, Ann! :smiley:

1 Like

Hello Ann, would you please provide the versions where this issue has been resolved?

Hi,

The underlying Jira ticket was resolved in early March. So versions released after that. If you’re on a current version you should be fine.

 
:slight_smile:
Ann