201 * drops {@code MODULE} access from the full capabilities mode. |
201 * drops {@code MODULE} access from the full capabilities mode. |
202 * |
202 * |
203 * @param targetClass the target class |
203 * @param targetClass the target class |
204 * @param caller the caller lookup object |
204 * @param caller the caller lookup object |
205 * @return a lookup object for the target class, with private access |
205 * @return a lookup object for the target class, with private access |
206 * @throws IllegalArgumentException if {@code targetClass} is a primitive type or array class |
206 * @throws IllegalArgumentException if {@code targetClass} is a primitive type or void or array class |
207 * @throws NullPointerException if {@code targetClass} or {@code caller} is {@code null} |
207 * @throws NullPointerException if {@code targetClass} or {@code caller} is {@code null} |
208 * @throws SecurityException if denied by the security manager |
208 * @throws SecurityException if denied by the security manager |
209 * @throws IllegalAccessException if any of the other access checks specified above fails |
209 * @throws IllegalAccessException if any of the other access checks specified above fails |
210 * @since 9 |
210 * @since 9 |
211 * @spec JPMS |
211 * @spec JPMS |
1383 } |
1383 } |
1384 |
1384 |
1385 private Lookup(Class<?> lookupClass, Class<?> prevLookupClass, int allowedModes) { |
1385 private Lookup(Class<?> lookupClass, Class<?> prevLookupClass, int allowedModes) { |
1386 assert prevLookupClass == null || ((allowedModes & MODULE) == 0 |
1386 assert prevLookupClass == null || ((allowedModes & MODULE) == 0 |
1387 && prevLookupClass.getModule() != lookupClass.getModule()); |
1387 && prevLookupClass.getModule() != lookupClass.getModule()); |
1388 |
1388 assert !lookupClass.isArray() && !lookupClass.isPrimitive(); |
1389 this.lookupClass = lookupClass; |
1389 this.lookupClass = lookupClass; |
1390 this.prevLookupClass = prevLookupClass; |
1390 this.prevLookupClass = prevLookupClass; |
1391 this.allowedModes = allowedModes; |
1391 this.allowedModes = allowedModes; |
1392 } |
1392 } |
1393 |
1393 |
1441 * which may change due to this operation. |
1441 * which may change due to this operation. |
1442 * <p> |
1442 * <p> |
1443 * @param requestedLookupClass the desired lookup class for the new lookup object |
1443 * @param requestedLookupClass the desired lookup class for the new lookup object |
1444 * @return a lookup object which reports the desired lookup class, or the same object |
1444 * @return a lookup object which reports the desired lookup class, or the same object |
1445 * if there is no change |
1445 * if there is no change |
|
1446 * @throws IllegalArgumentException if {@code requestedLookupClass} is a primitive type or void or array class |
1446 * @throws NullPointerException if the argument is null |
1447 * @throws NullPointerException if the argument is null |
1447 * |
1448 * |
1448 * @revised 9 |
1449 * @revised 9 |
1449 * @spec JPMS |
1450 * @spec JPMS |
1450 * @see #accessClass(Class) |
1451 * @see #accessClass(Class) |
1451 * @see <a href="#cross-module-lookup">Cross-module lookups</a> |
1452 * @see <a href="#cross-module-lookup">Cross-module lookups</a> |
1452 */ |
1453 */ |
1453 public Lookup in(Class<?> requestedLookupClass) { |
1454 public Lookup in(Class<?> requestedLookupClass) { |
1454 Objects.requireNonNull(requestedLookupClass); |
1455 Objects.requireNonNull(requestedLookupClass); |
|
1456 if (requestedLookupClass.isPrimitive()) |
|
1457 throw new IllegalArgumentException(requestedLookupClass + " is a primitive class"); |
|
1458 if (requestedLookupClass.isArray()) |
|
1459 throw new IllegalArgumentException(requestedLookupClass + " is an array class"); |
|
1460 |
1455 if (allowedModes == TRUSTED) // IMPL_LOOKUP can make any lookup at all |
1461 if (allowedModes == TRUSTED) // IMPL_LOOKUP can make any lookup at all |
1456 return new Lookup(requestedLookupClass, null, FULL_POWER_MODES); |
1462 return new Lookup(requestedLookupClass, null, FULL_POWER_MODES); |
1457 if (requestedLookupClass == this.lookupClass) |
1463 if (requestedLookupClass == this.lookupClass) |
1458 return this; // keep same capabilities |
1464 return this; // keep same capabilities |
1459 int newModes = (allowedModes & FULL_POWER_MODES); |
1465 int newModes = (allowedModes & FULL_POWER_MODES); |