Wednesday, August 15, 2012

Eclipse Extract Method Not All Paths End In Return

Here's an almost interesting find. I had code like the following:
[statements]
if (...) {
  return;
}
[statements]
if (...) {
  return;
}
[statements, but not 'return;']
Did 'Extract Method' on the above section. Got an error for "Not All Paths End In Return", even though refactoring should work fine.

No big deal. Actually it makes sense, since refactoring means not to change meaning, and refactored meaning should probably be along this line:
refactoredMethod(...); return; 

And by that reasoning the error is good. But it so happened that in my attempted refactoring, the continuation of the refactored section had no more code, just getting out of the method, so the refactoring in my mind (no return in front) wouldn't have changed the meaning, if you follow me.

Anyhow. I just pushed the refactoring forward, overriding the error.


No comments:

Post a Comment