Bug 6977 organize imports imports unnecessary classes
I'm talking about integration build of December 11: Here is a code (for jdk1.4): ------------ import java.io.IOException; public class test1 { static Thread thr = new Thread() { public void run() { System.out.println("Shutting down"); try { int c = System.in.read(); System.out.println(c); } catch (IOException e) { } } }; int o = 5; /** * Method main. * * @param args */ public static void main(String[] args) { Runtime r = Runtime.getRuntime(); r.traceInstructions(true); r.traceMethodCalls(true); r.addShutdownHook(thr); System.out.println("Available procs: " + r.availableProcessors ()); System.out.println("Free Memory: " + r.freeMemory()/1024 + "Kb"); System.out.println("Total Memory: " + r.totalMemory()/1024 + "Kb"); System.out.println("Max Memory: " + r.maxMemory()/1024 + "Kb"); System.getProperties().list(System.out); try { System.in.read(); } catch (Exception e) { } } } ---------- end of example code ------ Pressing CTRL+SHIFT+O to organize imports adds the following two imports: import sun.security.krb5.internal.r; import sun.security.krb5.internal.crypto.c; for the "c" and "r" VARIABLES!. This is a bad bad thing...... Surprisingly it skips the "o" field....
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest.java
if (selection[k].getFullyQualifiedName().equals(choices[i])) {
							found= selection[k];
						}
					}
					assertNotNull(name + "-query-notfound" + i, found);
					res[i]= found;
				}
				return res;
			}
		};
	}
	
	private void assertImports(ICompilationUnit cu, String[] imports) throws Exception {
		IImportDeclaration[] desc= cu.getImports();
		assertTrue(cu.getElementName() + "-count", desc.length == imports.length);
		for (int i= 0; i < imports.length; i++) {
			assertEquals(cu.getElementName() + "-cmpentries" + i, desc[i].getElementName(), imports[i]);
		}
	}
	
	public void test1() throws Exception {
		ICompilationUnit cu= (ICompilationUnit) fJProject1.findElement(new Path("junit/runner/BaseTestRunner.java"));
		assertNotNull("BaseTestRunner.java", cu);
		
		IPackageFragmentRoot root= (IPackageFragmentRoot)cu.getParent().getParent();
		IPackageFragment pack= root.createPackageFragment("mytest", true, null);
		
		ICompilationUnit colidingCU= pack.getCompilationUnit("TestListener.java");
		colidingCU.createType("public abstract class TestListener {\n}\n", null, true, null);