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