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

Bug 360789

Summary: Organize imports changes static imports to .* even when that introduces compile errors
Product: [Eclipse Project] JDT Reporter: Jorn Hertsig <jorn86>
Component: CoreAssignee: John Glassmyer <eclipse>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: eclipse.sprigogin, jorn86, markus.kell.r, remy.suen, satyam.kandula, shankhba
Version: 3.7   
Target Milestone: 4.5 M6   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 430303    

Description Jorn Hertsig CLA 2011-10-13 06:27:17 EDT
Build Identifier: I20110613-1736

I have two enums with similarly named fields:
enum Horizontal {TOP, CENTER, BOTTOM}
enum Vertical {LEFT, CENTER, RIGHT}

I have code that uses them like this:

import Horizontal.TOP;
import Vertical.CENTER;

// in some method
setAlignment(TOP, CENTER);

I have the organize imports action configured to replace static imports with .* whenever there's 1 or more. (Window menu -> Preferences -> Java -> Code Style -> Organize Imports -> Number of static imports needed for .* = 1)

Now, organizing imports will change the imports to:
import Horizontal.*;
import Vertical.*;

Since Horizontal also offers a CENTER constant, my method call no longer compiles, since it expects an instance of Horizontal and one of Vertical, and it now gets two of Horizontal.

Reproducible: Always

Steps to Reproduce:
1. Organize imports in code and settings as described above
Comment 1 Remy Suen CLA 2011-10-13 07:48:20 EDT
Java tooling bugs go to JDT.
Comment 2 Jorn Hertsig CLA 2012-03-20 06:00:20 EDT
Thanks for moving this to the correct product, but is someone going to take a look at it?
Comment 3 Satyam Kandula CLA 2012-03-20 07:03:53 EDT
I confirm that this is a bug which needs to be fixed. However, we may not be able to look at this right now. Please feel free to contribute a patch.
Comment 4 Markus Keller CLA 2015-03-05 14:55:23 EST
Fixed via bug 430303.
Comment 5 shankha banerjee CLA 2015-03-18 02:59:19 EDT
Verified for 4.5 M6 with build I20150316-2000