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

javac fails to compile call to public varargs method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 5.0, 6u10
    • tools
    • b40
    • generic, x86
    • generic, linux
    • Not verified

      FULL PRODUCT VERSION :
      java version "1.6.0_06"
      Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
      Java HotSpot(TM) Server VM (build 10.0-b22, mixed mode)

      Also tested on 1.6.0_10-rc:
      java version "1.6.0_10-rc"
      Java(TM) SE Runtime Environment (build 1.6.0_10-rc-b28)
      Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux arachne 2.6.24-19-generic #1 SMP Fri Jul 11 23:41:49 UTC 2008 i686 GNU/Linux
      Ubuntu 8.04.1


      A DESCRIPTION OF THE PROBLEM :
      Javac fails to compile a class containing a call to a public method with a varargs argument, when another applicable method with protected access modifier (i.e. not accessible) is present in the callee type.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create p1/Caller.java with this content:
      --- BEGIN p1/Caller.java ---
      package p1;

      import p2.Callee;

      public class Caller {
      public void bar() {
      Callee.foo(new Object());
      }
      }
      --- END p1/Caller.java ---

      Create p2/Caller.java with this content:
      --- BEGIN p2/Callee.java ---
      package p2;

      public class Callee {
      public static void foo(final Object... varargs) {
      };

      protected static void foo(final Object singleArg) {
      };
      }
      --- END p2/Callee.java ---

      Try to compile both using "javac p1/Caller.java p2/Callee.java".

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No warnings/errors, class files are generated, call to the varargs method is generated.
      ACTUAL -
      The compiler fails to compile the source code, producing no class files.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      p1/Caller.java:7: foo(java.lang.Object) has protected access in p2.Callee
      Callee.foo(new Object());
                            ^
      1 error


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      --- BEGIN p1/Caller.java ---
      package p1;

      import p2.Callee;

      public class Caller {
      public void bar() {
      Callee.foo(new Object());
      }
      }
      --- END p1/Caller.java ---

      --- BEGIN p2/Callee.java ---
      package p2;

      public class Callee {
      public static void foo(final Object... varargs) {
      };

      protected static void foo(final Object singleArg) {
      };
      }
      --- END p2/Callee.java ---

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

      CUSTOMER SUBMITTED WORKAROUND :
      Remove the protected method or change it's name or signature so that it is no longer applicable to the call.

            mcimadamore Maurizio Cimadamore
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: