Bug 197164

Summary: Incorrect hint: Cast xxx to int
Product: java Reporter: devon_c_miller <devon_c_miller>
Component: HintsAssignee: Jan Lahoda <jlahoda>
Status: VERIFIED FIXED QA Contact: issues <issues.netbeans.org>
Priority: P2 CC: mmirilovic
Version: 7.0   
Target Milestone: 7.0.1   
Hardware: PC   
OS: Windows XP   
Whiteboard: 70patch1-verified
Issue Type: DEFECT Exception Report:

Description devon_c_miller 2011-03-28 17:42:15 UTC
Dev 201103260400

Given this code:
    Object o = 42;
    int i = o;

A hint is displayed for the second line:
    "Case o to int"

If the suggested hint is applied, you get
    int i = (int)o;

This is incorrect as a ReferenceType cannot be cast to a PrimitiveType.

This displays no error indication in the editor, but javac reports:
    NewClass.java:15: inconvertible types
    found   : java.lang.Object
    required: int
            int i = (int)o;

Expeced behavior:
    "Case o to Integer"
and
    int i = (Integer)o;

Note: for pre-JDK 5 sources, the change needs to be:
    int i = ((Integer)o).intValue();
Comment 1 Jan Lahoda 2011-04-14 10:14:56 UTC
This has been changed in 1.7 javac (i.e. the cast in valid in 1.7), but is missing a source level check.
Comment 2 Jan Lahoda 2011-05-09 15:24:20 UTC
The fix in (nb-)javac:
http://hg.netbeans.org/main/nb-javac/rev/4c5f13798b8d
Integrating the nb-javac into NetBeans IDE:
http://hg.netbeans.org/jet-main/rev/d0a27b4198cf

I think this might be a good candidate for a patch, but none of the changesets above should be applied directly. The (nb-)javac patch would need to be applied to a branch nb-javac and rebuilding the nb-javac. Please let me known if this should be done. Thanks.
Comment 3 Jaromir Uhrik 2011-05-16 20:58:44 UTC
Verified in the trunk build #Build 201105160400. The changes seem to be clear so I don't see any reason to give it up. So Honzo, please rebuild and integrate. Thanks.
Comment 4 Jan Lahoda 2011-05-17 12:13:53 UTC
Applied to release70_fixes:
http://hg.netbeans.org/releases/rev/367b82e4118e
Spec. versions and long descriptions updated:
http://hg.netbeans.org/releases/rev/ab821ef74098
Comment 5 Jaromir Uhrik 2011-05-19 14:28:43 UTC
Verified in the following build + patch1:
Product Version: NetBeans IDE 7.0 (Build 201104080000)
Java: 1.6.0_25; Java HotSpot(TM) Client VM 20.0-b11
System: Windows 7 version 6.1 running on x86; Cp1250; cs_CZ (nb)
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo