Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 109282

Summary: [extract method] rejected selection followed by "break"
Product: [Eclipse Project] JDT Reporter: Ran Ettinger <ran.ettinger>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: akiezun
Version: 3.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Ran Ettinger CLA 2005-09-12 08:21:35 EDT
Trying to apply the Extract Method refactoring on the following selection 
results in an unnecessary rejection.

Original program: 

  private int g(boolean b) {
    int n = 10;
    int i = 0;
    while (i < n) {
      if (b) {
        // Extract Method from here
        i++;
        n -= i;
	// to here
        break;
      }
      else i++;
    }
    return n;
  }

Applying Extract Method on the selected code (signalled by the comments)
results in a rejection with the message: "Ambiguous return value: selected 
block contains more than one assignment to local variable".

In fact, because of the "break" statement, only the modified local variable n 
should be returned. The local variable i will never be relevant on return from 
the extracted method. As a result, variable i can be localized in the new 
method.

I expected the refactored source to look like this:

  private int g(boolean b) {
    int n = 10;
    int i = 0;
    while (i < n) {
      if (b) {
        n = newMethod(i, n);
        break;
      }
      else i++;
    }
    return n;
  }

  private int newMethod(int i, int n) {
    i++;
    n -= i;
    return n;
  }
Comment 1 Dirk Baeumer CLA 2005-09-12 10:27:22 EDT
*** Bug 109285 has been marked as a duplicate of this bug. ***
Comment 2 Adam Kiezun CLA 2006-03-23 09:06:39 EST
once this is fixed, the fan website should get updated too :)
http://progtools.comlab.ox.ac.uk/projects/refactoring/bugreports/eclipse
Comment 3 Eclipse Genie CLA 2020-03-25 05:18:07 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.