--- old/test/java/lang/invoke/MethodHandles/privateLookupIn/test/p/PrivateLookupInTests.java 2017-02-07 13:13:59.688047705 +0000 +++ new/test/java/lang/invoke/MethodHandles/privateLookupIn/test/p/PrivateLookupInTests.java 2017-02-07 13:13:59.523036374 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -126,6 +126,26 @@ Object obj = mh.invokeExact(); } + // test target class in unnamed module + public void testTargetClassInUnnamedModule() throws Throwable { + Class clazz = Class.forName("Unnamed"); + assertFalse(clazz.getModule().isNamed()); + + // thisModule does not read the unnamed module + Module thisModule = getClass().getModule(); + assertFalse(thisModule.canRead(clazz.getModule())); + try { + MethodHandles.privateLookupIn(clazz, MethodHandles.lookup()); + assertTrue(false); + } catch (IllegalAccessException expected) { } + + // thisModule reads the unnamed module + thisModule.addReads(clazz.getModule()); + Lookup lookup = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup()); + assertTrue(lookup.lookupClass() == clazz); + assertTrue(lookup.hasPrivateAccess()); + } + // test does not read m2, m2 opens p2 to test @Test(expectedExceptions = {IllegalAccessException.class}) public void testCallerDoesNotRead() throws Throwable {