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 221350 - dereferencing null Pointer sometimes bad with ternary expressions
Summary: dereferencing null Pointer sometimes bad with ternary expressions
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.3
Hardware: All All
: P3 normal with 1 vote (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-02 13:29 UTC by mklaehn
Modified: 2012-11-07 15:18 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 mklaehn 2012-11-02 13:29:42 UTC
private int doStuffTernaryGood(final Collection<Object> objects) {
    return ((null != objects) && !objects.isEmpty())
            ? objects.iterator().next().hashCode()
            : 0;
}

the above works as expected.

If on the other hand the condition is the complement as in the folowing code

private int doStuffTernaryBad(final Collection<Object> objects) {
    return ((null == objects) || objects.isEmpty())
            ? 0
            : objects.iterator().next().hashCode();
}

objects.iterator() is marked with a hint of "Dereferencing null pointer".
Comment 1 Quality Engineering 2012-11-04 02:50:53 UTC
Integrated into 'main-golden', will be available in build *201211040001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/508e3c0500c4
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #221350: handle conditional expression similarly to ifs.
Comment 2 Jan Lahoda 2012-11-05 06:45:57 UTC
Fixed by the above changeset, thanks for the report.
Comment 3 mklaehn 2012-11-07 15:18:52 UTC
verified with
Product Version: NetBeans IDE Dev (Build nbms-and-javadoc-9532-on-20121106)
Java: 1.7.0_10-ea; Java HotSpot(TM) 64-Bit Server VM 23.6-b04
Runtime: Java(TM) SE Runtime Environment 1.7.0_10-ea-b13