fb-contrib icon indicating copy to clipboard operation
fb-contrib copied to clipboard

PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS false positive for Java8 .stream()

Open hesch opened this issue 4 years ago • 1 comments

Collection<String> test(Collection<String> input) {
    List<String> aPrefix = input.stream().map(x -> "a" + x).collect(toList());
    List<String> bPrefix = input.stream().map(x -> "b" + x).collect(toList());
    aPrefix.addAll(bPrefix);

    return aPrefix;
}

In the above example I get a PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS for the method stream()Ljava/util/stream/Stream; I don't think this is correct, as streams cannot be reused.

hesch avatar May 15 '20 08:05 hesch

Adding the stream method to https://github.com/mebigfatguy/fb-contrib/blob/d8c62f30273297a702c96ac39bc1d6f878eb2914/src/main/java/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java#L176 should help get rid of this error. But maybe that list is not the best one since it has another purpose, and another one called nonReusables should be created and used.

lasselindqvist avatar Sep 14 '20 09:09 lasselindqvist

i believe this was fixed awhile back. please try 7.6.2, and reopen if it's still broken. sorry about not updating.

mebigfatguy avatar Dec 03 '23 03:12 mebigfatguy