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

Misleading 'cannot be accessed from outside package' diagnostic for inconsistent varargs override

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 10
    • 8, 9
    • tools
    • None
    • b34

      javac reports a 'cannot be accessed from outside package' diagnostic for the following program, which is misleading because A.f is declared and accessed in the same package.

      Note that the program contains an inconsistent varargs override: B.f should be `f(int...)`, not `f(int[])`.

      === T.java
      package test;
      class A {
        void f(int... x) {}
      }
      class B extends A {
        @Override void f(int[] x) {}
      }
      class T {
        {
          new B().f(1);
        }
      }
      ===

      $ javac -fullversion T.java
      javac full version "9+179"
      T.java:10: error: f(int...) is not public in A; cannot be accessed from outside package
          new B().f(1);
                 ^
      1 error

            vromero Vicente Arturo Romero Zaldivar
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: