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.
Summary: | Incorrect reporting of "Unnecessary test for null" hint | ||
---|---|---|---|
Product: | java | Reporter: | esmithbss <esmithbss> |
Component: | Hints | Assignee: | Jan Lahoda <jlahoda> |
Status: | VERIFIED FIXED | ||
Severity: | normal | CC: | ban.nobuhiro, mclaborn, mmirilovic |
Priority: | P3 | ||
Version: | 7.3 | ||
Hardware: | PC | ||
OS: | Windows 7 | ||
Issue Type: | DEFECT | Exception Reporter: | |
Attachments: | IDE log |
Description
esmithbss
2013-03-20 21:17:08 UTC
Created attachment 132875 [details]
IDE log
I have a similar problem. Here is the code for reproducing the bug. ---- begin package netbeans; import java.util.List; public class NullHint { public void foo(List<Object> objs) { Object bar = null; for (Object obj : objs) { System.err.println(obj); if (bar == null) { bar = new Object(); } } // if objs is empty, bar is null here. if (bar != null) { // NB7.3 says this check is unnecessary System.err.println(); } } } ---- end Another example: // code is completely dummy; just to demo the "Unnecessary test for null" warning private String demoNullHint(Object object, String argument, String defaultValue) { if (object==null && (argument==null || argument.equals("test"))) { return defaultValue; } // warning here: "Unnecessary test for null" if (object!=null) { // if } else { // else } return "some value"; } I'll push fixes for the first two usecases into the trunk soon. The last usecase is a duplicate of bug #227954. Integrated into 'main-golden', will be available in build *201304172301* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/d7c433595615 User: Jan Lahoda <jlahoda@netbeans.org> Log: #227745: NPECheck hints must properly handle enhanced for loops. v. Backported to release73 branch: http://hg.netbeans.org/releases/rev/58284df11288 Integrated into 'releases', will be available in build *201305042200* or newer. Wait for official and publicly available build. Changeset: http://hg.netbeans.org/releases/rev/58284df11288 User: Jan Lahoda <jlahoda@netbeans.org> Log: #227745: NPECheck hints must properly handle enhanced for loops. *** Bug 229490 has been marked as a duplicate of this bug. *** |