Menu

#1412 UnusedPrivateMethod false positive: Issue #1403 not completely solved

PMD-5.4.0
closed
None
PMD
3-Major
Bug
5.3.4
2015-09-22
2015-09-21
Rei Angelus
No

Hello,

There is still one case with false positive on the UnusedPrivateMethod rule (issue #1403): if the 2 private methods have the same name.

For example:

 <test-code>
        <description>#1403 (BIS) False positive UnusedPrivateMethod with JAVA8</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Something {
    private Purse annPurse5;
    private Purse bobPurse7;

    @Before public void setUp() {
        modifiableEmptyMap = new HashMap<>();

        annPurse5 = new Purse(ANN, 5);
        bobPurse7 = new Purse(BOB, 7);
    }

    @Test public void mapMergeShouldReturnTheUnionWhenGivenDifferentSetsWithSomeCommonValues() {
        final Map<String, Purse> actual
            = Combiners.mapMerge(mapOf(annPurse5, bobPurse7), mapOf(bobPurse9, calPurse10), ADDITION);
        assertEquals(mapOf(annPurse5, bobPurse16, calPurse10), actual);
    }
    private static Map<String, Purse> mapOf(final Purse... values) {
        return mapOf(Purse::getOwner, values);
    }
    private static <K, V> Map<K, V> mapOf(final Function<V, K> keyMapper, final V... values) {
        return Stream.of(values).collect(Collectors.toMap(keyMapper, Function.identity()));
    }
}
        ]]></code>
    </test-code>
Thanks,

Discussion

  • Andreas Dangel

    Andreas Dangel - 2015-09-22
    • summary: Issue #1403 not completely solve --> UnusedPrivateMethod false positive: Issue #1403 not completely solved
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -3,8 +3,9 @@
     There is still one case with false positive on the UnusedPrivateMethod rule (issue #1403): if the 2 private methods have the same name.
    
     For example:
    +
    +~~~~~
     :::xml
    -
      <test-code>
             <description>#1403 (BIS) False positive UnusedPrivateMethod with JAVA8</description>
             <expected-problems>0</expected-problems>
    @@ -34,5 +35,6 @@
     }
             ]]></code>
         </test-code>
    -    
    +~~~~~
    +
         Thanks,
    
    • status: open --> in-progress
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.4.0
     
  • Andreas Dangel

    Andreas Dangel - 2015-09-22

    Thanks for retesting. Unfortunately, the bugfix requires some bigger changes to the symbol table implementation, so I'm applying the fix for 5.4.0.

    For the time being, there is an awkward workaround - swap the definition of the two methods and the false positive probably goes away...

     
  • Andreas Dangel

    Andreas Dangel - 2015-09-22
    • status: in-progress --> closed
     

Log in to post a comment.