Name: igT44549 Date: 03/03/99
public class classtest {
public static void main(String[] argv) {
System.out.println(int.class.getName());
System.out.println(Integer.class.getName());
}
}
This is a small test file that I used in order to test
the difference between Integer.class and int.class. The bytecode
generated for Integer.class includes a field called
class$java$lang$Integer of type java.lang.Class.
So, I added a field to my class to see if I could expose a bug:
what if I added a field of the same name, but different type?
public class classtest {
int class$java$lang$Integer;
public static void main(String[] argv) {
System.out.println(int.class.getName());
System.out.println(Integer.class.getName());
}
}
Trying to compile, I see this error:
[Tue 2:01pm ] abegel@boojum> /usr/java1.2/bin/javac classtest.java
classtest.java:7: Incompatible type for int. Can't convert int to null.
System.out.println(Integer.class.getName());
^
classtest.java:7: Incompatible type for =. Can't convert java.lang.Class to int.
System.out.println(Integer.class.getName());
^
classtest.java:7: Can't invoke a method on a int.
System.out.println(Integer.class.getName());
^
3 errors
[Tue 2:03pm ] abegel@boojum>
This shows me that the compiler defers to the user-declared
field (as far as type is concerned) but doesn't realize to change
the name of the generated field to something unique that won't
clash. Thus, Integer.class fails because the generated code used
the user-declared field that had the incorrect type.
That's a compiler bug.
It happened in the javac in these two packages:
java full version "Solaris_JDK_1.1.6_04_pre-release"
and
java full version "Solaris_JDK_1.2_01_dev06_fcsV"
(Review ID: 54986)
======================================================================
- duplicates
-
JDK-4094180 # Synthetic names can conflict with explicit declaration
- Closed