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
Depends on:
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:


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) {
        else {
            if (obj == null) {

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