Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 100593 - [quick fix] proposes wrong cast from Object to primitive int
Summary: [quick fix] proposes wrong cast from Object to primitive int
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M2   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-17 11:27 EDT by Markus Keller CLA
Modified: 2009-08-06 15:03 EDT (History)
2 users (show)

See Also:


Attachments
patch (10.56 KB, patch)
2008-10-21 09:02 EDT, Benjamin Muskalla CLA
markus.kell.r: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2005-06-17 11:27:04 EDT
I20050617-0010

    void m(Object obj) {
        int i= obj;
    }

In a 5.0 project, a quick fix proposes 'Add cast to (int)', which is wrong. The
right cast here would be to (Integer), which would then be autounboxed.

In a 1.4 project, no 'Add cast ..' quick fix is proposed, which is correct.
Comment 1 Benjamin Muskalla CLA 2008-10-21 09:02:58 EDT
Created attachment 115687 [details]
patch

Here is a little patch for this issue.
I refactored out the boxing conversion into a static method to avoid having duplicate logic in the quick fix and the preview.
Comment 2 Leopold Welsch CLA 2008-10-29 03:58:30 EDT
I am wondering if the patch solves as well (JDK1.6) the problem with

Integer mu=5.0f

cause the proposal here has to be (int) and not Integer.

Additionally I am interested if the proposed fix works as well with 

   Object obj=true;
    boolean mu=   obj;

I guess the patch should apply to all primitives.
Comment 3 Markus Keller CLA 2009-08-06 12:00:15 EDT
Released to HEAD with a few corrections.


(In reply to comment #2)
> I am wondering if the patch solves as well (JDK1.6) the problem with
> 
> Integer mu=5.0f
> 
> cause the proposal here has to be (int) and not Integer.

That's bug 285573.

> Additionally I am interested if the proposed fix works as well with 
> 
>    Object obj=true;
>     boolean mu=   obj;
> 
> I guess the patch should apply to all primitives.

Yes, fixes all primitives.
Comment 4 Markus Keller CLA 2009-08-06 15:03:33 EDT
While looking a bit closer at bug 285573, I realized that the existing code actually used ITypeBinding#isCastCompatible(ITypeBinding type) the wrong way 'round and this worked only with huge luck. I reworked the fix a bit in HEAD.