Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 349276 - [inline][quick fix] Inline Local Variable changes semantics if initializer is not a pure function
Summary: [inline][quick fix] Inline Local Variable changes semantics if initializer is...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 402605 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-06-14 03:24 EDT by Raksha Vasisht CLA
Modified: 2020-01-09 09:12 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raksha Vasisht CLA 2011-06-14 03:24:24 EDT
BETA_JAVA7

List<Integer> m() {    	
    	HashMap<String, ArrayList<Integer>> field= new HashMap<>();
    	field.put("hi", new ArrayList<Integer>());
    	return  (ArrayList<Integer>)field.get(0);		
}

ctrl+ 1 on field -> Inline Local Variable shown on field declaration, which is wrong and gives a wrong result.

Also in this case:

List<Integer> m() {    	
    	HashMap<String, ArrayList<Integer>> field= new HashMap<>();
    	return null;
}

If the local variable is marked unused, ILV is offered as a quick fix and the declaration is removed. Doing this in the refactoring is ok if explicitly invoked, but should not be offered as a quick fix here.

Also seen earlier to 1.5,

List m() {
    	List list= new ArrayList();
    	list.add(0);
    	return list;
}

We should check code at:

org.eclipse.jdt.internal.corext.refactoring.code.InlineTempRefactoring.checkAssignments(VariableDeclaration)
Comment 1 Markus Keller CLA 2011-06-14 08:21:01 EDT
This is similar to bug 257714.
Comment 2 Markus Keller CLA 2013-03-07 13:14:03 EST
*** Bug 402605 has been marked as a duplicate of this bug. ***
Comment 3 Eclipse Genie CLA 2020-01-09 09:12:56 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.