Menu

#1403 False positive UnusedPrivateMethod with JAVA8

PMD-5.3.4
closed
None
PMD
3-Major
Bug
2015-09-14
2015-09-11
Rei Angelus
No

There is a false positive UnusedPrivateMethod with this kind of code :

public class Something {
    @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()));
    }
}

Maybe because of Java 8 "mapOf(Purse::getOwner, values)" or private called by private ?

Thanks,

Discussion

  • Andreas Dangel

    Andreas Dangel - 2015-09-14
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,7 +1,7 @@
     There is a false positive UnusedPrivateMethod with this kind of code :
    
    +~~~~~
     :::java
    -
     public class Something {
        @Test public void mapMergeShouldReturnTheUnionWhenGivenDifferentSetsWithSomeCommonValues() {
             final Map<String, Purse> actual
    @@ -17,6 +17,7 @@
             return Stream.of(values).collect(Collectors.toMap(keyMapper, Function.identity()));
         }
     }
    +~~~~~
    
     Maybe because of Java 8 "mapOf(Purse::getOwner, values)" or private called by private ?
    
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.3.4
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.