3

I have a public method foo() and a private method bar() in the same class.

foo() is the only caller but it clearly invokes bar() but IntelliJ shows a violation of this rule, squid:UnusedPrivateMethod, for the method declaration of bar():

Remove this unused private 'bar' method.

My setup:

  • IntelliJ IDEA 2016.3.5 with SonarLint 2.8.0.1735
  • SonarLint is connected (connected mode) to a SonarQube 5.6.5 instance which does not identify these violations(!)
  • foo() has an @Override declaration. I don't know if this has any impact but could be useful info

It appears to be a bug in SonarLint. Can someone confirm?

Update: In this case not a public method using it, but the same problem

Alix
  • 2,630
  • 30
  • 72
  • Can you include a minimal reproducible example? I suspect there are some important details missing here. A concrete example would clear that up. In any case, this kind of false positive may happen when the Java scanner doesn't see some of the compiled classes. So make sure the project is compiled, and verify that the `.class` files of the class with this issue, and other classes referenced by it are all present in the filesystem. – janos Mar 11 '17 at 11:14
  • I could not reproduce the issue with a no-arg method but here is a screenshot: http://imgur.com/a/xijao – Alix Mar 13 '17 at 07:57
  • In your screenshot, I don't see the definition of `getString`. If the return type of this method is not visible, the Java analyzer cannot know for sure that `foo(getString(...))` is referring to the `foo` method of the class, or some other `foo` method somewhere else. Since I don't see where `getString` comes from, I suspect the code is not compiled. When the code is not compiled, the `.class` files don't exist, and the Java analyzer cannot find the bytecode it needs, which often results in this kind of false positive. So -> compile your project! (and verify the relevant `.class` files exist) – janos Mar 13 '17 at 09:08
  • getString() is defined in the superclass Activity (Android builtin API). I did make sure to compile (ctrl+F9) – Alix Mar 13 '17 at 09:21
  • To clarify, getString() is defined in android.content.Context which is one of the super classes of android.app.Activity – Alix Mar 13 '17 at 11:24
  • Thanks, that's quite clear. Somebody from the Java analyzer team will get back to you. – janos Mar 13 '17 at 12:39
  • @janos Hi, any follow-up on this? Was this fixed? – Alix Dec 15 '17 at 11:26

0 Answers0