184 * @throws NullPointerException if {@code targetClass} or {@code caller} is {@code null}
185 * @throws IllegalAccessException if the access check specified above fails
186 * @throws SecurityException if denied by the security manager
187 * @since 9
188 * @spec JPMS
189 * @see Lookup#dropLookupMode
190 */
191 public static Lookup privateLookupIn(Class<?> targetClass, Lookup lookup) throws IllegalAccessException {
192 SecurityManager sm = System.getSecurityManager();
193 if (sm != null) sm.checkPermission(ACCESS_PERMISSION);
194 if (targetClass.isPrimitive())
195 throw new IllegalArgumentException(targetClass + " is a primitive class");
196 if (targetClass.isArray())
197 throw new IllegalArgumentException(targetClass + " is an array class");
198 Module targetModule = targetClass.getModule();
199 Module callerModule = lookup.lookupClass().getModule();
200 if (!callerModule.canRead(targetModule))
201 throw new IllegalAccessException(callerModule + " does not read " + targetModule);
202 if (targetModule.isNamed()) {
203 String pn = targetClass.getPackageName();
204 assert pn.length() > 0 : "unnamed package cannot be in named module";
205 if (!targetModule.isOpen(pn, callerModule))
206 throw new IllegalAccessException(targetModule + " does not open " + pn + " to " + callerModule);
207 }
208 if ((lookup.lookupModes() & Lookup.MODULE) == 0)
209 throw new IllegalAccessException("lookup does not have MODULE lookup mode");
210 if (!callerModule.isNamed() && targetModule.isNamed()) {
211 IllegalAccessLogger logger = IllegalAccessLogger.illegalAccessLogger();
212 if (logger != null) {
213 logger.logIfOpenedForIllegalAccess(lookup, targetClass);
214 }
215 }
216 return new Lookup(targetClass);
217 }
218
219 /**
220 * Performs an unchecked "crack" of a
221 * <a href="MethodHandleInfo.html#directmh">direct method handle</a>.
222 * The result is as if the user had obtained a lookup object capable enough
223 * to crack the target method handle, called
224 * {@link java.lang.invoke.MethodHandles.Lookup#revealDirect Lookup.revealDirect}
|
184 * @throws NullPointerException if {@code targetClass} or {@code caller} is {@code null}
185 * @throws IllegalAccessException if the access check specified above fails
186 * @throws SecurityException if denied by the security manager
187 * @since 9
188 * @spec JPMS
189 * @see Lookup#dropLookupMode
190 */
191 public static Lookup privateLookupIn(Class<?> targetClass, Lookup lookup) throws IllegalAccessException {
192 SecurityManager sm = System.getSecurityManager();
193 if (sm != null) sm.checkPermission(ACCESS_PERMISSION);
194 if (targetClass.isPrimitive())
195 throw new IllegalArgumentException(targetClass + " is a primitive class");
196 if (targetClass.isArray())
197 throw new IllegalArgumentException(targetClass + " is an array class");
198 Module targetModule = targetClass.getModule();
199 Module callerModule = lookup.lookupClass().getModule();
200 if (!callerModule.canRead(targetModule))
201 throw new IllegalAccessException(callerModule + " does not read " + targetModule);
202 if (targetModule.isNamed()) {
203 String pn = targetClass.getPackageName();
204 assert !pn.isEmpty() : "unnamed package cannot be in named module";
205 if (!targetModule.isOpen(pn, callerModule))
206 throw new IllegalAccessException(targetModule + " does not open " + pn + " to " + callerModule);
207 }
208 if ((lookup.lookupModes() & Lookup.MODULE) == 0)
209 throw new IllegalAccessException("lookup does not have MODULE lookup mode");
210 if (!callerModule.isNamed() && targetModule.isNamed()) {
211 IllegalAccessLogger logger = IllegalAccessLogger.illegalAccessLogger();
212 if (logger != null) {
213 logger.logIfOpenedForIllegalAccess(lookup, targetClass);
214 }
215 }
216 return new Lookup(targetClass);
217 }
218
219 /**
220 * Performs an unchecked "crack" of a
221 * <a href="MethodHandleInfo.html#directmh">direct method handle</a>.
222 * The result is as if the user had obtained a lookup object capable enough
223 * to crack the target method handle, called
224 * {@link java.lang.invoke.MethodHandles.Lookup#revealDirect Lookup.revealDirect}
|