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

Bug 251471

Summary: [clean up][quick assist] Remove unused local variables leaves cast (compile error)
Product: [Eclipse Project] JDT Reporter: Sebastian.Buchwald
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, dvice_null, markus.kell.r, phoen1x
Version: 3.4.1Keywords: helpwanted
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Sebastian.Buchwald CLA 2008-10-20 16:00:42 EDT
Build ID: M20080911-1700

Steps To Reproduce:
1. Create a new "Bug" class (see attachment):

import java.util.HashSet;
import java.util.Set;

public class Bug {  
	public static void main(String[] args) {
		Set bla = null;
		bla = (Set)new HashSet();
	}
}

2. Source -> Clean up
3. Use a profile with "Remove unused local variables" activated

More information:
The code should looks like

import java.util.HashSet;
import java.util.Set;

public class Bug {  
	public static void main(String[] args) {
		(Set)new HashSet();
	}
}

which isn't valid java code.
If you remove the "(Set)"-cast the code will be valid.
Comment 1 Dani Megert CLA 2009-06-25 02:39:38 EDT
You indicated in comment 0 that you are using M20080911-1700, which is 3.4.1, so please stop changing the version.
Comment 2 Alexey Mising name CLA 2009-10-15 02:37:06 EDT
This bug still reproduce in 20090920-1017 (3.5.1)

Map insertMap = new LinkedHashMap();
This code after clean-up set to
new LinkedHashMap();

But if i use qiuck fix (Ctrl-1), a have choose beetwen 2 type of remove this variable
I need can set this option in clen-up settings.
Comment 3 Markus Keller CLA 2009-11-04 05:29:31 EST
(In reply to comment #2)
We're not going to offer the other quick assist as clean up, since it does not always preserve behavior.
Comment 4 Alexey Mising name CLA 2009-11-09 06:39:47 EST
(In reply to comment #3)

I'm sorry, you didn't understand me. I meant that in my opinion it is not correct that clean-up function always uses 
option which transfers this kind of code: 
Map insertMap = new LinkedHashMap(); 
to ->
new LinkedHashMap();
while when I use quick fix it offers me two oppotunities of remove-action (total removing or transformation to the form mentioned before).
So I'd like to have some option in clen-up settings where I could choose the type of result I expect this line will have after conversion.
Comment 5 Markus Keller CLA 2009-11-09 08:55:17 EST
(In reply to comment #4)
I did understand your request, but that's not the subject of this bug.

You would have to open a new enhancement request for comment 2, but as I said, we're not going to add that, so if you open an enhancement request, it will be closed as WONTFIX.
Comment 6 Deepak Azad CLA 2012-04-09 08:04:50 EDT
*** Bug 374083 has been marked as a duplicate of this bug. ***
Comment 7 Eclipse Genie CLA 2019-12-10 07:23:30 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.