Bug 285551

Summary: [extract method] "Ambiguous return value" error when extracting Expression from ExpressionStatement
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: ASSIGNED --- QA Contact:
Severity: normal    
Priority: P3 CC: b.muskalla, daniel_megert, deepakazad, raksha.vasisht, reprogrammer
Version: 3.6   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Markus Keller CLA 2009-08-04 06:16:35 EDT
I20090803-1800

FUP to bug 213519.

ArrayList<Integer> list = new ArrayList<Integer>();
for (Integer var: list) {}
int a = 0;
for (int c = 0; c < 10; c++) {
   list.add(a++);
}
System.out.println(list.toString());

- Select 'list.add(a++)' (without the ';' at the end)
- Extract Method
=> Strange "Ambiguous return value" error

Expected: Same behavior as when I select the whole ExpressionStatement. Or at least a better error message.
Comment 1 Markus Keller CLA 2009-08-05 10:33:28 EDT
Strictly spoken, the behavior is correct. But we should be more helpful.

Without the ';', only the expression 'list.add(a++)' is selected, and the return value of the extracted method should be
1. the value of the expression (boolean, see return type of List#add(Object))
and
2. the value of 'a', since that variable is modified in the extracted method body

One solution could be to always expand the selection in the first place if it occurs in an ExpressionStatement. But this would prevent correct duplicates search in case the selected expression is used in another context (not in an ExpressionStatement).

We should just be smarter in the case we know we will fail. In that case, we should not abort with an error dialog, but automagically expand the selection to include the ';'.

I first thought we should inform the user about that, but I guess it's OK to just be smart without a witty message.
Comment 2 Dani Megert CLA 2011-04-12 06:30:19 EDT
Ping! Benny, any plans to work on this?
Comment 3 Eclipse Genie CLA 2020-08-15 17:48:24 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.

If you have further information on the current state of the bug, please add it. 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.
Comment 4 Eclipse Genie CLA 2023-01-02 00:19:16 EST
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.

If you have further information on the current state of the bug, please add it. 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.