0

I am using Sonarlint V3.5.0 in Spring Tool Suite. I am receiving the squid:S1186 warning when I have the default constructor inside the code like this:

public class TestClass{
    public TestClass() {}
}

It is a little bit annoying to have this warning all the time. As I have found, SonarSource have solved this as a bug in version 3.5, But the newest Sonarlint still gives me this warning.

How can I solve this using Sonarlint? Thanks.

Rann Lifshitz
  • 4,040
  • 4
  • 22
  • 42
MenAmy
  • 3
  • 1
  • 4

1 Answers1

1

You can not remove the rule check using SonarLint by itself. You can ignore the offending rule using a SonarQube server and connect your SonarLint to the SQ server in order to ignore the rule, as suggested here.

As stated in the OP, the SonarSource team is having issues with the use-case described in the question.

Please consider the following BEFORE thinking of ignoring the rule:

The squid:S1186 issue is a good practice concept - having an empty scope in general in our code, not just in a constructor, is a code anti-pattern.

In your case, the default constructor has been explicitly implemented, which is apparently required by the Sprint Tool Suite you are using (this sort of use case is discussed nicely here).

Considering the fact that the empty scope is indeed an anti-pattern, I would suggest adding a comment inside the constructor's empty scope explaining that the explicit public default constructor is required due to the usage of STS.

Doing this will obviously solve the issue raised by SonarLint.

In case you have many instances of auto-generated empty default constructors - you should be able to use your IDEs find/replace solution with a regexp in order to replace the empty scopes with scopes containing a comment explaining why this is so.

Rann Lifshitz
  • 4,040
  • 4
  • 22
  • 42