JDK-8077786 : Check varargs access against inferred signature
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u40,9
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2015-04-14
  • Updated: 2015-09-29
  • Resolved: 2015-04-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u60Fixed 9 b61Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
Accessibility of the varargs array element is supposed to be tested against "the last formal parameter type of the invocation type of the method" (JLS 15.12.3).  That is, the inferred type, not necessarily the declared type.  This is consistent with the generated bytecode, which allocates an array based on the inferred varargs type.  (JLS 15.12.4.2 is ambiguous about the declared/inferred distinction for generated bytecode, but javac consistently uses the inferred type.)

Since 8u40, per JDK-8036953, the varargs access check is performed on the declared element type only.  This leads to runtime errors.

Example:

-----
public class Test {
    static <T> void varargs(T... ts) { System.out.println(ts); }

    public static void main(String... args) {
        varargs(p2.Other.getPrivate());
    }

}

-----
package p2;

public class Other {
    public static Iterable<Private> getPrivate() { return null; }
    private class Private {}
}

-----
javac 8u20: compiler error
javac 8u40: compiles, IllegalAccessError at runtime