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

javac erroneously accept ambiguous field reference

XMLWordPrintable

    • b96
    • x86
    • linux
    • Verified

      FULL PRODUCT VERSION :
      Solaris/Sparc (Sun JDK):
      java version "1.4.2_05"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
      Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)

      Linux/x86 (Sun JDK):
      java version "1.4.2_07"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_07-b05)
      Java HotSpot(TM) Client VM (build 1.4.2_07-b05, mixed mode)

      Darwin/PPC (Apple JDK):
      java version "1.5.0_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-56)
      Java HotSpot(TM) Client VM (build 1.5.0_02-36, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Sun JDK:
      SunOS [HOST] Generic_106541-34 sun4u sparc SUNW,Ultra-Enterprise
      Linux [HOST] 2.6.10-1.771_FC2smp #1 SMP Mon Mar 28 01:10:51 EST 2005 i686 i686 i386 GNU/Linux

      Apple JDK:
      Darwin Kernel Version 8.2.0: Fri Jun 24 17:46:54 PDT 2005; root:xnu-792.2.4.obj~3/RELEASE_PPC

      A DESCRIPTION OF THE PROBLEM :
      The java compiler incorrectly inlines inherited static final fields, also failing to apply correct disambiguation rules.

      In presence of multiply inherited fields (through interfaces), the value javac choses to inline violates the JVM spec, and is inconsistent with other fields resolved at run-time (or the same field resolved through reflection).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the provided source code:
      javac Main.java
      java Main

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1 -> int (compile-time)
      1 -> Object (run-time)
      1 -> reflected int (run-time)
      1 -> reflected Object (run-time)

      (same value weather resolved at run-time or compile-time)
      ACTUAL -
      0 -> int (compile-time)
      1 -> Object (run-time)
      1 -> reflected int (run-time)
      1 -> reflected Object (run-time)

      (value resolved at compile-time by javac is inconsistent with values resolved at run-time)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      interface A {
          int i = 1;
          Object o = new Integer(1);
      }

      interface B {
          int i = 2;
          Object o = new Integer(2);
      }

      interface C extends A, B {
      }

      class D {
          public static final int i = 0;
          public static final Object o = new Integer(0);
      }

      class Main extends D implements C {
          public static void main(String[] args) throws Throwable {
              System.out.println(Main.i + " -> int (compile-time)");
              System.out.println(Main.o + " -> Object (run-time)");
              System.out.println(Main.class.getField("i").get(null) + " -> reflected int (run-time)");
              System.out.println(Main.class.getField("o").get(null) + " -> reflected Object (run-time)");
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Its a rather convoluted example, just don't use it.

            mcimadamore Maurizio Cimadamore
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: