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

javac generates code that fails byte code verification for the varargs feature

    Details

    • Subcomponent:
    • Introduced In Version:
      5.0
    • Resolved In Build:
      b130
    • CPU:
      x86
    • OS:
      linux
    • Verification:
      Verified

      Description

      FULL PRODUCT VERSION :
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
      Java HotSpot(TM) Server VM (build 1.5.0_03-b07, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux 2.4.9-e.25kmap1enterprise #1 SMP

      A DESCRIPTION OF THE PROBLEM :
      suppose class A is package private, class B is public and in
      the same package as A and extends A, a public method on B
      has the signature of foo(A... args).

      class C is in a different package, and has an invocation of
       foo(new B(), new B())

      class C will compile, but the resulting byte code does not run
      (gets an java.lang.IllegalAccessError), since javac would
      generate a new A[] call for class C for the varargs invocation.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile the source code included below,
       run it as follows:

      java -Xfuture -classpath [classpath pointing to the classfiles] p2.C

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      should fail to compile since p2.C doesn't have access to
      p1.A
      ACTUAL -
      compiler generated no error, but when java is invoked on
      the resulting class file (with the -Xfuture option, or if classes
      in p2 and p1 are loaded from different file system pathes),
      you get a runtime error:
      Exception in thread "main" java.lang.IllegalAccessError: tried to access class p1.A from class p2.C
              at p2.C.main(C.java:6)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.IllegalAccessError: tried to access class p1.A from class p2.C
              at p2.C.main(C.java:6)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      A.java
      ----------
      package p1;

      class A {
        A() {
        }
      }
      ------------

      B.java
      ------------
      package p1;
      import java.io.*;
      public class B extends A {
       public B() {}

       public void foo(A... args) {
        System.out.println(args);
       }
      }
      -----------

      C.java
      ----------
      package p2;
      import p1.B;
      public class C {

       public static final void main(String[] args) {
         (new B()).foo(new B(), new B());
       }
      }
      ---------


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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                mmma Marvin Ma (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: