JDK-4217110 : javac isn't robust enough when compiling Integer.class
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1999-03-04
  • Updated: 1999-03-18
  • Resolved: 1999-03-18
Related Reports
Duplicate :  
Description

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

Comments
WORK AROUND Name: igT44549 Date: 03/03/99 don't name your fields the same name that the compiler is using for generated code. ======================================================================
11-06-2004

EVALUATION Reproducible in JDK1.1.7, JDK1.2, and JDK1.2.1. -------------------------------------------------- TEST: c_integer/IntegerTest.java JDK under test: java full version "JDK-1.2.2-H" (/usr/local/java/jdk1.2.2/solaris) ACTION: compile -- Failed. Compilation failed REASON: User specified action: run compile IntegerTest.java TIME: 7.955 seconds STDOUT: STDERR: /home/iag/work/bug/c_integer/IntegerTest.java:14: Incompatible type for int. Can't convert int to null. System.out.println(Integer.class.getName()); ^ /home/iag/work/bug/c_integer/IntegerTest.java:14: Incompatible type for =. Can't convert java.lang.Class to int. System.out.println(Integer.class.getName()); ^ /home/iag/work/bug/c_integer/IntegerTest.java:14: Can't invoke a method on a int. System.out.println(Integer.class.getName()); ^ 3 errors TEST RESULT: Failed. Compilation failed -------------------------------------------------- iris.garcia@eng 1999-03-03 A duplicate of the synthetic names bugs: 4094180 and 4098167 iris.garcia@eng 1999-03-17
03-03-1999