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

Compiler generates invalid class files

XMLWordPrintable

    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0_01-b06)
      Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

      The same problem also exists (tested) with JDK 5.0 Update 3 and Update 11

      ADDITIONAL OS VERSION INFORMATION :
      (OS independent)
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      For a generic class definining two type variables the compiler produces an illegal class file.

      The first type variable (T) defines a bound on two interfaces (IA and IB).

      The second type variable (X) defines the first type variable (T) as its bound.

      (My code declares also a third type variable (Y) with the first type variable (T) as its bound - this third type variable is the point of the whole construct, but contributes nothing to the problem)

      In the generated class files all calls to methods on IA and IB are delegated to IA, ie:

      IA contains m1();
      IB contains m2();

      A call of ib.m2() is compiled into "invokeinterface IA.m2", which fails at runtime.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the supplied source code and start it.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The code should run without problems
      ACTUAL -
      The run is aborted with a stack trace

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.NoSuchMethodError: java.lang.Runnable.compareTo(Ljava/lang/Object;)I
              at Tester.test(Main.java:6)
              at Main.test(Main.java:35)
              at Main.main(Main.java:25)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /* Main.java */
      abstract class Tester<T extends Runnable & Comparable<T>,
              X extends T> {
          public void test() {
              X x = createX();
              x.compareTo(null);
              x.run();
          }
          protected abstract X createX();
      }

      interface IBoth extends Comparable<IBoth>, Runnable {
      }

      class MyTester implements IBoth {
          public int compareTo(IBoth o) {
              return 0;
          }
          public void run() {
          }
      }

      public class Main {
          public static void main(String[] args) {
              new Main().test();
          }
          public void test() {
              Tester<IBoth, MyTester> mu =
                  new Tester<IBoth, MyTester>() {
                      @Override
                      protected MyTester createX() {
                          return new MyTester();
                      }
              };
              mu.test();
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      1. If you own IA then let IA extend IB

      2. use the compiler from Eclipse - its not subject to this bug

            Unassigned Unassigned
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: