A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/2796 below:

[java] UnusedAssignment false positive with call chains · Issue #2796 · pmd/pmd · GitHub

Affects PMD Version: 6.26.0

Description:

Call chains where side-effects occur in arguments are not handled by UnusedAssignment. This is a known issue, described here

// For the record this has problems with call chains with side effects, like // a.foo(a = 2).bar(a = 3);

It's hard to make this right on master, because of the grammar for expressions. But this is easily fixed in #2794

Code Sample demonstrating the issue:

class Test {
    int a() {
        int a = 10;
        try {
            // both method calls may throw, so a = 2 and a = 4 reach after the try,
            // but not a = 10
            "".substring(a = 2)
              .substring(a = 4);
        } catch (RuntimeException e) {
        }
        return a;
    }
}

We get

line 3:	The initializer for variable 'a' is never used (overwritten on line 7)
line 7:	The value assigned to variable 'a' is never used (overwritten on line 8)

but only the first warning is relevant, the other one is a FP


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4