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

Calling vararg method when inferred parameter type not accessible doesn't cause compilation error

XMLWordPrintable

      Please consider next source code:
      //file A.java
      package outer;

      public class A {

          protected static class InnerA
          {
          }
      }

      //file B.java
      package outer;

      public class B extends A.InnerA {

          public <T extends A.InnerA> void foo(T... args)
          {
          }
      }

      //file Test.java
      package outer.test;

      import outer.B;

      public class Test {

          public static void main(String[] args) {
              B b = new B();
              b.foo(new B());
          }
      }

      JLS 15.12.3 says that "If the compile-time declaration is applicable by variable arity invocation, then where the last formal parameter type of the invocation type of the method is Fn[], it is a compile-time error if the type which is the erasure of Fn is not accessible at the point of invocation."

      Since A.InnerA is not accessible at the point of invocation, compilation should fail but after JDK-8075520 no compiler time error or runtime exception occurs.

            dlsmith Dan Smith
            snikandrova Svetlana Nikandrova (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: