History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEA-16773
Type: Bug Bug
Status: Open Open
Assignee: Dmitry Jemerov
Reporter: Eugene Kirpichov
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
IDEA: Feedback

Extract variable inside short-circuit boolean expressions sometimes is not semantics-preserving

Created: 27 Dec 07 15:01   Updated: 27 Dec 07 16:01
Component/s: Refactoring

Build: 7,590
Severity: High


 Description  « Hide
Consider the code

if(x == null || x.size() == 0) { doSomething(); continue; }
System.out.println(x.size());

Let us extract the variable x.size().

I get:
int size = x.size();
if(x == null || size == 0) {...

This obviously has different semantics when x is null.

I don't see a semantics-preserving variant that would not cause code duplication of the 'then' clause, so I suggest to give out a warning dialog in such cases, or possibly to refuse doing such a dangerous 'refactoring' at all.



 All   Comments   Work Log   Change History      Sort Order:
There are no comments yet on this issue.