JDK-7054590 : (JSR-292) MethodHandleProxies.asInterfaceInstance() accepts private/protected nested interfaces
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 7,7u4
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,linux,os_x
  • CPU: generic,x86
  • Submitted: 2011-06-14
  • Updated: 2012-03-29
  • Resolved: 2012-03-29
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 7 JDK 8
7u4 b10Fixed 8Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
The javadoc specification for the MethodHandleProxies.asInterfaceInstance method states:
  "The interface must be public. No additional access checks are performed."

However, this method still accepts private/default-access/protected *nested* interfaces.

Minimized test:
===============
--- Test.java ---
import java.lang.invoke.*;
import static java.lang.invoke.MethodType.*;
import static java.lang.invoke.MethodHandles.*;
import static java.lang.invoke.MethodHandleProxies.*;

public class Test {
   /*protected*/ /*private*/ interface PrivateIntf {
       void m();
   }

   public static class C {
       public static void m() {}
   }

   public static void main(String argv[]) throws Throwable {
       MethodHandle mh = lookup().findStatic(
               C.class, "m", methodType(void.class));

       PrivateIntf intf = asInterfaceInstance(PrivateIntf.class, mh);
   }
}
--- Test.java ---

Minimized test output:
======================
$ java -showversion -verify Test
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b145)
Java HotSpot(TM) Server VM (build 21.0-b15, mixed mode)

Comments
EVALUATION Correct. We have a fix in hand for this.
14-06-2011