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

Bug 198586

Summary: [quick fix] Add cast casts to wrong type if incorrect type is in same package
Product: [Eclipse Project] JDT Reporter: Neale Upstone <neale>
Component: UIAssignee: Benno Baumgartner <benno.baumgartner>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: benno.baumgartner, Olivier_Thomann
Version: 3.3   
Target Milestone: 3.4 M1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
fix none

Description Neale Upstone CLA 2007-08-01 16:29:12 EDT
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:
Comment 1 Olivier Thomann CLA 2007-08-01 17:06:59 EDT
Move to JDT/UI
Comment 2 Benno Baumgartner CLA 2007-08-02 06:03:24 EDT
Created attachment 75202 [details]
fix
Comment 3 Benno Baumgartner CLA 2007-08-02 06:11:12 EDT
fixed > I20070731-0800
Comment 4 Neale Upstone CLA 2007-08-02 08:09:42 EDT
Holy **** guys.  Is there a competition for the fastest turnaround from bug report to fix?

If so, I think you might have won.

Nice work!
Comment 5 Benno Baumgartner CLA 2007-08-02 08:18:43 EDT
:-) Thanks! It's a simple fix and it is less work to fix it right away then to look at it again, that's all.
Comment 6 Neale Upstone CLA 2008-10-16 09:31:22 EDT
Closing.  Verified in Eclipse 3.4.1