This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 267508 - Static Analysis does not understand |= operator
Summary: Static Analysis does not understand |= operator
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.1
Hardware: All All
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-09 17:12 UTC by bondolo
Modified: 2016-11-13 02:53 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bondolo 2016-08-09 17:12:00 UTC
The java source static analysis believes that done is not referenced in the "bad" method. Using "done = done |" rather than "done |=" works as expected.

public class FlowFailure {

    public static void bad(String... args) {
        boolean done = false;
        long counting = 0;
        while (!(done |= Thread.currentThread().isInterrupted())) {
            counting++;
            done = counting > 1_000_000_000;
        }
    }

    public static void good(String... args) {
        boolean done = false;
        long counting = 0;
        while (!(done = done | Thread.currentThread().isInterrupted())) {
            counting++;
            done = counting > 1_000_000_000;
        }
    }


}
Comment 1 Svata Dedic 2016-11-10 14:12:00 UTC
Good catch. In addition, the 'bad' method does not report that the value assigned to 'done' is actually unused. Done itself _is_ used, the _value_ of the |= operation is also used (to control the cycle) but the copy assigned to 'done' variable is never fetched again.

I'll make an additional hint + fix for this case, in addition to fixing the reported error.
Comment 2 Svata Dedic 2016-11-10 15:32:14 UTC
Implemented as jet-main#3842dbadbb65
Comment 3 Quality Engineering 2016-11-13 02:53:15 UTC
Integrated into 'main-silver', will be available in build *201611130001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/3842dbadbb65
User: Svata Dedic <sdedic@netbeans.org>
Log: #267508: unused values from compound assignments are reported. Fix to change comp. assignment to expression provided.