intellij java false positive on Unused "private" methods should be removed

823 views
Skip to first unread message

Travis

unread,
Aug 23, 2016, 12:57:36 PM8/23/16
to SonarLint
since the latest update(2.3), we are seeing Unused "private" methods should be removed in seemingly random places... they do not appear on the server or using eclipse plugin.
i haven't found a real pattern to the failures, it seems to be when calling methods in the arguments...

here is an example(the classes must be in two files):
Test.java:
package some.package;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Test {
 
private static final Logger LOGGER = LoggerFactory.getLogger(Test.class);

 
private Test(){}

 
public static void test(Something something) {
 testError
(something.getString());
 
}

 
private static void testError(String someString) {
 LOGGER
.info(someString);
 
}
}


Something.java:
package some.package;

public class Something {
 
public String getString() {
 
return "test";
 
}
}

you should get the Unused "private" methods should be removed error: Remove this unused private "testError" method.

jtie...@gmail.com

unread,
Aug 23, 2016, 4:09:43 PM8/23/16
to SonarLint, thy...@gmail.com
Hi,

We do value the standard courtesies around here. People tend to get grumpy when they're not nicely greeted :)
Your issue is related to a regression with SonarLint 2.3 in which the configuration system is not picking up the JavaConfiguration classes causing the bytecode to be missing.
Over here: https://groups.google.com/d/msg/sonarqube/56TMG6Hyyxk/SEdaqh5nAAAJ is a test build available with the fix. Please give it a shot!

Kind regards,

Johan.

thy...@gmail.com

unread,
Aug 23, 2016, 4:22:25 PM8/23/16
to SonarLint, thy...@gmail.com, jtie...@gmail.com
ha, sorry about that... i got so focused on making the test case :).
thanks for the awesome tools and the fix!

Travis

thy...@gmail.com

unread,
Aug 23, 2016, 5:10:14 PM8/23/16
to SonarLint, thy...@gmail.com, jtie...@gmail.com
hello again,

looks like SonarLint 2.4-build948 does fix the false positive if not bound to a remote SonarQube server, but it still showing when i am connected.
is this the same issue as teamcity mentioned in the other case?

Thanks,
Travis

thy...@gmail.com

unread,
Aug 23, 2016, 7:59:20 PM8/23/16
to SonarLint, thy...@gmail.com, jtie...@gmail.com
And a little more info:
looks like the 2.4-build948 does fix most of the issue, the only time it seems to be failing now is just with my test case where they are both new files. so i am guessing it can't compare with the server somehow?
it seems to not show the issue if the "Something" class were already committed to the project(and i assume processed by sonarqube).
hope this helps, but the bigger issue seems fixed.

Thanks again,
Travis

jtie...@gmail.com

unread,
Aug 24, 2016, 2:16:37 AM8/24/16
to SonarLint, thy...@gmail.com, jtie...@gmail.com
Hi,

For connected mode it's also important to know that the plugin version of the server will be used and no longer the local version (SonarLint 2.3 has Java Plugin 4.1 if I recall correctly). So please check that your server is not running an old version (Although I'm not sure if that rule was affected in the last couple of versions).
Also in your case of the 'new' files: please ensure that your files are compiled, otherwise it will not provide the bytecode (as it can't provide it because it's not there) and still trigger this FP.

Kind regards,

Johan.

thy...@gmail.com

unread,
Aug 24, 2016, 11:20:13 AM8/24/16
to SonarLint, thy...@gmail.com, jtie...@gmail.com
Hey there,
you are right! somehow it was not compiled... so looks like everything is good here. nice job!
thanks for your time and energy explaining it all to me :),
Travis

Johan "Johnnei"

unread,
Aug 24, 2016, 1:28:56 PM8/24/16
to SonarLint, thy...@gmail.com, jtie...@gmail.com
Hi,

I'm glad to be of help!

Kind regards,

Johan.
Reply all
Reply to author
Forward
0 new messages