False failure with "Avoid unused private methods"
A source code analyzer
Brought to you by:
adangel,
juansotuyo
The warning "Avoid unused private methods such as 'endTest(SourceLocation,String,Object...)'." is generated for the following method:
private void endTest(final SourceLocation sourceLocation, final String message, final Object... params)
Despite the following two calling being made within the same class.
TestCore.getInstance().endTest(sourceLocation, "", (Object[]) null);
TestCore.getInstance().endTest(sourceLocation, format, params);
I think, the problem here is, that PMD's type resolution capability is very limited.
PMD does not know, that TestCore.getInstance() actually returns a TestCore instance, where your endTest method is declared.
I think, you can help out PMD, if you write it that way:
Let me know, if this works for you.
Thanks,
Andreas
We have the same problem since we have updated from PMD 5.0.5 to 5.1.
Perhaps in our case it is a problem that the method is in an abstract base class. It is a private void method and will be called from the same abstract class.
Unfortunately I can't reproduce it.
Could you please change the file
Something.java, so that PMD reports the methodfooas unused?See attachment: https://sourceforge.net/p/pmd/bugs/1156/attachment/Something.java
Last edit: Andreas Dangel 2014-04-26
I have updated to PMD 5.1.1. The problem does not occur anymore in my environment.
Last edit: Manfred Koch 2014-05-02
I have seen a lot of new false positives about unused private methods since updating to 5.1.2 from 5.1.1. We use the org.tigris.gef library, and an example is in the UndoManager.java class. http://gef.tigris.org/source/browse/gef/trunk/src/org/tigris/gef/undo/UndoManager.java?view=log (attached that version)
The method getBoolString is marked as unused but it is called from a couple of places. I haven't been able to really reduce this test case, any major changes "fix" the problem. In general I'd say that new false positives seem to be from call sites in while or for loops.
I didn't get a response from the OP - but the problem is fixed for Manfred and I fixed Richard's problem (getBool method wasn't detected correctly).
Please note, that with 5.1.3-SNAPSHOT, three other bug have been fixed: [#1228] and [#1233] and [#1234], so the situation with the next version should be much better.
I'm closing this ticket now and assume the problem is fixed with the next PMD release.
Related
Issues:
#1228Issues:
#1233Issues:
#1234I have tested the version 5.1.3. The problem still exists. It is hard to create a test class for the problem.
I can reproduce it too wiyth this code :
Last edit: Fabrice Daugan 2014-09-13