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.
The class below gives an "Unnecessary test for null" hint on the if statement. This is because of the assert. However, the hint is only valid if assertions are actually enabled. And since assertions are not enabled by default, I believe the hint is inappropriate in this case. class Names { public static void main(String[] args) { String name = getName(); assert (name != null); if (name != null) { System.out.println("Hello, " + name); } } static String getName() { return null; } }
In general asserts are put into the code to declare invariants which the programmer thinks should be true. By inserting an assert statement, the programmer explicitly says the variable should not be null after, and the IDE should work with that information. The actual runtime checks are irrelevant -- the code as it is written is broken. One can use assert to trigger debugging code, like boolean debug = false; assert debug = true; if (debug) { ... } or similar thing, but I think these are rather misuses of the assert statement. In the experimental implementation of issue #249320, several modes to analyze asserts are available in the analysis engine, including your approach - but no UI :) so I'll keep this defect as a reminder to provide user option to tune the analysis.