#1156 False failure with "Avoid unused private methods"


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);

1 Attachments


  • Andreas Dangel

    Andreas Dangel - 2014-02-01

    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:

    TestCore instance = TestCore.getInstance();
    instance.endTest(sourceLocation, "", (Object[]) null);

    Let me know, if this works for you.


  • Andreas Dangel

    Andreas Dangel - 2014-02-01
    • status: open --> more-info-needed
    • assigned_to: Andreas Dangel
  • Manfred Koch

    Manfred Koch - 2014-03-17

    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.

  • Manfred Koch

    Manfred Koch - 2014-05-02

    I have updated to PMD 5.1.1. The problem does not occur anymore in my environment.

    Last edit: Manfred Koch 2014-05-02
  • Richard Quirk

    Richard Quirk - 2014-08-11

    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.

  • Andreas Dangel

    Andreas Dangel - 2014-08-18

    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.



    Issues: #1228
    Issues: #1233
    Issues: #1234

  • Andreas Dangel

    Andreas Dangel - 2014-08-18
    • status: more-info-needed --> closed
    • Milestone: New Tickets --> PMD-next
    • Affects version: 3.0.1 --> 5.0.1
  • Manfred Koch

    Manfred Koch - 2014-09-03

    I have tested the version 5.1.3. The problem still exists. It is hard to create a test class for the problem.

  • Fabrice Daugan

    Fabrice Daugan - 2014-09-13

    I can reproduce it too wiyth this code :

    public class TestPrivate<T> {
        protected Object getProtected(final T bean) {
            return getPrivate(bean);
        private Object getPrivate(final Object bean) {
            return bean;
    Last edit: Fabrice Daugan 2014-09-13

Log in to post a comment.