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

Bug 365664

Summary: [extract method] [refactoring] The "Ambiguous return value: ..." error message could be more descriptive
Product: [Eclipse Project] JDT Reporter: Mohsen Vakilian <reprogrammer>
Component: UIAssignee: Deepak Azad <deepakazad>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: deepakazad, markus.kell.r, nchen, reprogrammer, snegara2
Version: 3.7.1   
Target Milestone: 3.8 M5   
Hardware: PC   
OS: All   
Whiteboard:

Description Mohsen Vakilian CLA 2011-12-05 15:49:54 EST
Build Identifier: 20110916-0149

Reproducible: Always

Steps to Reproduce:

1. Invoke the Extract Method refactoring by selecting the statements marked in the code below:
----
public class C {
  private int m() {
    int a;
    int b;
    // START SELECTION
    a = 1;
    b = 2;
    // END SELECTION
    return a + b;
  }
}
----
2. The refactoring tool will report the following message and prevent the user from continuing the refactoring:
"Ambiguous return value: Selected block contains more than one assignment to local variables. Affected variables are: int a, int b"

CodingSpectator <http://codingspectator.cs.illinois.edu> recorded the messages that the Eclipse refactoring tool reported to our participants. The above error message was the most frequent message that the Extract Method refactoring reported to our participants (See Bug 365129 for more information).

I'd like to propose a small change to the above error message to make it easier to understand. The cause of the above message isn't just the selection of assignments to multiple local variables. Rather, the problem is that the selected block contains assignments to multiple variables that are used outside the selection. For example, the Extract Method refactoring won't report any messages in the code below.

----
public class C {
  private int m() {
    int a;
    int b;
    // START SELECTION
    a = 1;
    b = 1;
    // END SELECTION
    return a;
  }
}
----

How about changing the above message to the following?

"Ambiguous return value: Selected statements contain more than one assignment to local variables that are used in the code following the selection. Affected variables are: int a, int b"
Comment 1 Deepak Azad CLA 2011-12-06 11:56:54 EST
(In reply to comment #0)
> How about changing the above message to the following?
> 
> "Ambiguous return value: Selected statements contain more than one assignment
> to local variables that are used in the code following the selection. Affected
> variables are: int a, int b"

While it is not hard to figure out why assignment to local variables is a problem, it does take some brain cycles and I do not see any harm in adding a few extra words to make this explicit.
Comment 2 Deepak Azad CLA 2011-12-16 08:40:26 EST
While this message is correct, it feels a bit too long.
"Ambiguous return value: Selected block contains more than one assignment to local variables that are used in the code following the selection. Affected variables are: int a, int b"

I am leaning towards changing this to..
"Ambiguous return value: Selected block modifies more than one local variable used in subsequent code. Affected variables are: int a, int b"
Comment 3 Mohsen Vakilian CLA 2011-12-16 08:50:47 EST
(In reply to comment #2)

> "Ambiguous return value: Selected block modifies more than one local variable
> used in subsequent code. Affected variables are: int a, int b"

Sounds good to me.

Note that this bug is related to Bug 365129.
Comment 4 Deepak Azad CLA 2011-12-16 13:06:49 EST
Fixed in master - 743a83b9b11ae23fa1c57ea45ed9c0901ec464ad