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

Bug 349276

Summary: [inline][quick fix] Inline Local Variable changes semantics if initializer is not a pure function
Product: [Eclipse Project] JDT Reporter: Raksha Vasisht <raksha.vasisht>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, deepakazad, markus.kell.r, oleg.tsvinev
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

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.