On 05/19/2017 05:58 AM, Peter Levart wrote:
Hi Nikolai,

On 05/19/2017 12:41 PM, Nicolai Parlog wrote:
  Hi!

I'm too lazy to try right now

It's easy. Take this example:

public class Test {
     public static void main(String[] args) throws Exception {
         Object theUnsafe = Class.forName("jdk.internal.misc.Unsafe")
                                 .getMethod("getUnsafe")
                                 .invoke(null);
     }
}

Running this on classpath without any additional JVM options produces:

Exception in thread "main" java.lang.IllegalAccessException: class Test cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @63d4e2ba at java.base/jdk.internal.reflect.Reflection.throwIllegalAccessException(Reflection.java:445) at java.base/jdk.internal.reflect.Reflection.throwIllegalAccessException(Reflection.java:436) at java.base/jdk.internal.reflect.Reflection.ensureMemberAccess(Reflection.java:112) at java.base/java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:407) at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:399)
     at java.base/java.lang.reflect.Method.invoke(Method.java:535)
     at Test.main(Test.java:9)

(note that the exception is thrown from Method.invoke)

When run with:

      --add-exports java.base/jdk.internal.misc=ALL-UNNAMED

...the example works (does not throw exception), but when run with:

     --add-opens java.base/jdk.internal.misc=ALL-UNNAMED

...the example still works!!!! OOOPS - this is a bug!!! This is definitely a bug.

This is seemingly consistent with the code run time code in Module for addOpens, which always seems to add export when open is added. It would be quite strange if the descriptor directives and JVM switches didn't match the run time code; is this something that the EG should talk about? Or is there a hidden logic to this?

--
- DML

Reply via email to