9

I updated my Sonar to Version 5.1.2, and the issue Methods should not be empty appears on this code:

public User() {}

public User (String login) {
   this.login = login;
}

It seems to be a bug. Am I right? Because this didn't happen before.

Ismael G.
  • 378
  • 1
  • 2
  • 10
  • What is the java plugin version ? what is the rule key of the issue raised? – benzonico Sep 17 '15 at 11:12
  • `Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation`. But this is a constructor. So is not required to have a implementation. Because if I do that, I will comment `do nothing`, which does not mean anything – Ismael G. Sep 17 '15 at 11:42
  • 1
    Can you precise the two information I asked ? Why would you need to explicitely declare an empty public constructor with no argument (if you remove this constructor your code will behave the same as it will be declared implicitely) ? – benzonico Sep 17 '15 at 12:35
  • 1
    Oh, now I understood. The rule key is squid:S1186, I need to declare explicitely an empty public constructor with no argument because I also need the default one, and if I don't declare it , it won't be avaliable. – Ismael G. Sep 17 '15 at 14:31
  • So, what version of the sonar-java plugin are you using ? as the bug you are refering to in your answer is fixed since last release. – benzonico Sep 17 '15 at 14:37
  • @benzonico Having this issue with java plugin 3.6. Btw, are you saying this rule is supposed to trigger only when the constructor is empty AND there's not other one? (Which I could agree is sensible indeed). – Baptiste Mathus Nov 05 '15 at 13:10
  • @BaptisteMathus please bring this discussion to sonarqube@googlegroups.com thanks. – benzonico Nov 05 '15 at 13:13
  • I am getting that too with Sonarqube 6.2! – Michail Michailidis Jan 22 '17 at 15:29

2 Answers2

8

I found this jira, It's a Sonar's Bug.

https://jira.sonarsource.com/browse/SONARJAVA-1138

Ismael G.
  • 378
  • 1
  • 2
  • 10
  • 2
    Well, after checking it seems it's not really that bug. Actually, this issue is already fixed. That may be this fix that made the current issue (re)appear/regress. But the link above is *not* the issue you need to wait to get resolved (since it's an old one). – Baptiste Mathus Nov 05 '15 at 13:06
0

It really seems to be unexpected behavior. I think it was the ticket response above what caused it. I'm trying to talk to the developer to set the S1186 rule. If you want to follow:

https://jira.sonarsource.com/browse/SONARJAVA-1138

  • please reach out to sonarqube@googlegroups.com instead of repeating an answer on SO or commenting on a closed ticket. Thanks. – benzonico Nov 05 '15 at 13:13