Please use the Apache issue tracking system for new NetBeans issues ( !!
Bug 197164 - Incorrect hint: Cast xxx to int
Incorrect hint: Cast xxx to int
Product: java
Classification: Unclassified
Component: Hints
PC Windows XP
: P2 (vote)
: 7.0.1
Assigned To: Jan Lahoda
Depends on:
  Show dependency treegraph
Reported: 2011-03-28 17:42 UTC by devon_c_miller
Modified: 2011-05-19 14:28 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT


Note You need to log in before you can comment on or make changes to this bug.
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: inconvertible types
    found   : java.lang.Object
    required: int
            int i = (int)o;

Expeced behavior:
    "Case o to Integer"
    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:
Integrating the nb-javac into NetBeans IDE:

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:
Spec. versions and long descriptions updated:
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