This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 193625 - Fixing cast with hint might give confusing result.
Summary: Fixing cast with hint might give confusing result.
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.0
Hardware: PC Windows Vista
: P3 normal (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-20 07:39 UTC by Chiana
Modified: 2011-01-13 00:57 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chiana 2010-12-20 07:39:54 UTC
[ BUILD # : 20101215 ]
[ JDK VERSION : 1.6.22 ]

Examine the following class;
import java.util.List;
/**
 * @author Kent
 */
public class mainClass {

  List<a1.NewClass> s2 =  needToBeCasted();

  private Object needToBeCasted() {
    return null;
  }
}
 - - -
It apparently need a typecase for the method call, but, when using the
error-hint to insert one the code will look like this;
mport a1.NewClass;
import java.util.List;
/**
 * @author Kent
 */
public class mainClass {

  List<a1.NewClass> s2 =  (List<NewClass>) needToBeCasted();

  private Object needToBeCasted() {
    return null;
  }
}
 - - -
As you see it has used the short form of NewClass even if it is specified fully
on the lVal and it has also added an import for the class, there is actually
nothing wrong with this, but, it can be very confusing if you have a lot of
classes with same name in different packages.
As I see it it the rVal should have the same specification of class as the
lVal.
Comment 1 Chiana 2010-12-20 07:52:15 UTC
Come to think of it, this could be a configurable warning; Explicit package on the left imported on the right.
Reason: If you have multiple packages with same name and erasure and you for some reason change the import statement the construct will no longer point to the correct package and thus give an error.
Comment 2 Jan Lahoda 2010-12-21 19:41:59 UTC
Copying the exact type specification in this case:
http://hg.netbeans.org/jet-main/rev/1a84ce109c2c
Comment 3 Quality Engineering 2010-12-23 07:08:46 UTC
Integrated into 'main-golden', will be available in build *201012230001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/1a84ce109c2c
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #193625: when creating cast in variable initializer, keep the exact variable's type in the cast.