Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4217110

javac isn't robust enough when compiling Integer.class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • tools
    • generic
    • generic



      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)
      ======================================================================

            iris Iris Clark
            iris Iris Clark
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: