Project: JDT
Bug 198586 [quick fix] Add cast casts to wrong type if incorrect type is in same package
Reported: 2007-08-01 16:29:12 | Status: closed fixed

Build ID: I20070621-1340 The assignment quick fix, "add cast" can break code if the cast is to a type that is also visible in the current package, and is used in the class. e.g. package org.bah; class MyClass { }; package com.foo; class MyClass { }; package com.foo; class MyOtherClass { org.bah.MyClass otherPackage ref = new Object(); // fails to compile MyClass localPackageRef; } When the quick fix is applied, it offers to cast to org.bah.MyClass, but inserts an import which then masks the local package MyClass and incorrectly changes its' type. The correct behaviour would be that no import statement is generated, and the line becomes: org.bah.MyClass otherPackage ref = (org.bah.MyClass)new Object(); More information:

Files changed in fix:
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CastCompletionProposal.java