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

Summary: Add refactoring to add null checks into multi-statement lines
Product: java Reporter: tomwheeler <tomwheeler>
Component: RefactoringAssignee: Jan Becicka <jbecicka>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 7.0.1   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

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:

   foo.getBar().doSomething();

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");
   }

   bar.doSomething();

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