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 200713 - Add refactoring to add null checks into multi-statement lines
Summary: Add refactoring to add null checks into multi-statement lines
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 7.0.1
Hardware: All All
: P3 normal (vote)
Assignee: Jan Becicka
Depends on:
Reported: 2011-08-05 18:09 UTC by tomwheeler
Modified: 2011-08-05 18:09 UTC (History)
0 users

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description tomwheeler 2011-08-05 18:09:27 UTC
This is somewhat related to issue #200712, but requests a different (and somewhat complementary) refactoring pattern.

Assume you have the following code:


This can produce a NullPointerException if either the 'foo' instance or the 'getBar()' method's return value is null.  I think NetBeans would benefit from having a refactoring pattern which will change this into a multi-line statement which checks for null, like:

   if (foo == null) {
       throw new NullPointerException("foo is null");

   Bar bar = foo.getBar();
   if (bar == null) {
       throw new NullPointerException("bar is null");


This will be quite helpful for working with legacy code, especially when it has undocumented or inconsistent standards for null return values.