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 200712 - Add refactoring to break up multi-statement lines
Summary: Add refactoring to break up multi-statement lines
Status: RESOLVED WORKSFORME
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 7.0.1
Hardware: All All
: P3 normal (vote)
Assignee: Ralph Ruijs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-05 17:53 UTC by tomwheeler
Modified: 2015-04-28 11:30 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tomwheeler 2011-08-05 17:53:20 UTC
Consider the following line of Java code:

   foo.getBar().doSomething();

If you have a NullPointerException stacktrace which identifies this line, it's not clear whether the 'foo' instance or the 'getBar()' method is null.

Probably the best way to avoid this is to have one statement per line, like:

   Bar bar = foo.getBar();
   bar.doSomething();

It's certainly desirable to do this for new code, but many times we find ourselves working with legacy code which puts several statements on a single line.  NetBeans would benefit from a refactoring pattern which splits these into one statement per line, as shown above.  The existing logic for the  "Assign Return Value To New Variable" quick fix hint would work quite well for naming the new instance variables created.
Comment 1 Ralph Ruijs 2015-04-28 11:30:23 UTC
Introduce variable on the expression works for me in this case.