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 249234 - Incorrect "Unnecessary test for null" when there is a ternary operator (?:) in the condition
Summary: Incorrect "Unnecessary test for null" when there is a ternary operator (?:) i...
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0.2
Hardware: PC All
: P4 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-09 15:18 UTC by attila.kelemen
Modified: 2015-08-11 14:40 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 attila.kelemen 2014-12-09 15:18:37 UTC
A ternary operator in the condition fools NetBeans null hints. For example, the code below generates an "Unnecessary test for null" warning in the else clause.

    private static void example(Object obj, boolean a, boolean b) {
        if (obj == null ? a : b) {
            System.out.println(a);
        }
        else {
            if (obj == null) {
                System.out.println(b);
            }
        }
    }

ps.: Given that such conditions are quite confusing, maybe a new hint is reasonable to avoid ternary in ifs.