diff --git a/src/java.base/share/classes/java/lang/Module.java b/src/java.base/share/classes/java/lang/Module.java index 9ca560cfcba..6f4da2219c1 100644 --- a/src/java.base/share/classes/java/lang/Module.java +++ b/src/java.base/share/classes/java/lang/Module.java @@ -597,6 +597,14 @@ public final class Module implements AnnotatedElement { * *

This method does not check if the given module reads this module.

* + * @apiNote A package {@code p} opened to module {@code M} allows code in + * {@code M} do {@linkplain java.lang.reflect.AccessibleObject#setAccessible(boolean) + * deep reflection} on all types in the package. + * Further, if {@code M} reads this module, it can obtain a + * {@link java.lang.invoke.MethodHandles.Lookup Lookup} object that is allowed to + * {@link java.lang.invoke.MethodHandles.Lookup#defineClass(byte[]) define classes} + * in package {@code p}. + * * @param pn * The package name * @param other @@ -650,6 +658,14 @@ public final class Module implements AnnotatedElement { * *

This method does not check if the given module reads this module.

* + * @apiNote A package {@code p} opened to module {@code M} allows code in + * {@code M} do {@linkplain java.lang.reflect.AccessibleObject#setAccessible(boolean) + * deep reflection} on all types in the package. + * Further, if {@code M} reads this module, it can obtain a + * {@link java.lang.invoke.MethodHandles.Lookup Lookup} object that is allowed to + * {@link java.lang.invoke.MethodHandles.Lookup#defineClass(byte[]) define classes} + * in package {@code p}. + * * @param pn * The package name * @@ -657,6 +673,8 @@ public final class Module implements AnnotatedElement { * unconditionally * * @see ModuleDescriptor#opens() + * @see java.lang.reflect.AccessibleObject#setAccessible(boolean) + * @see java.lang.invoke.MethodHandles#privateLookupIn */ public boolean isOpen(String pn) { Objects.requireNonNull(pn); diff --git a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java index 7795ccadb6c..7199dd59476 100644 --- a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java @@ -233,6 +233,12 @@ public class MethodHandles { *

* The resulting {@code Lookup} object has no {@code ORIGINAL} access. * + * @apiNote The {@code Lookup} object returned by this method is allowed to + * {@linkplain Lookup#defineClass(byte[]) define classes} in the runtime package + * of {@code targetClass}. Extreme caution should be taken when opening a package + * to another module as such defined classes have the same full privilege + * access as other members in {@code targetClass}'s module. + * * @param targetClass the target class * @param caller the caller lookup object * @return a lookup object for the target class, with private access @@ -851,7 +857,7 @@ public class MethodHandles { *

* {@link MethodHandles#privateLookupIn(Class, Lookup) MethodHandles.privateLookupIn(T.class, lookup)} * can be used to teleport a {@code lookup} from class {@code C} to class {@code T} - * and create a new {@code Lookup} with private access + * and produce a new {@code Lookup} with private access * if the lookup class is allowed to do deep reflection on {@code T}. * The {@code lookup} must have {@link #MODULE} and {@link #PRIVATE} access * to call {@code privateLookupIn}. @@ -869,6 +875,12 @@ public class MethodHandles { * it cannot be used to obtain another private {@code Lookup} by calling * {@link MethodHandles#privateLookupIn(Class, Lookup) privateLookupIn} * because it has no {@code MODULE} access. + *

+ * The {@code Lookup} object returned by {@code privateLookupIn} is allowed to + * {@linkplain Lookup#defineClass(byte[]) define classes} in the runtime package + * of {@code T}. Extreme caution should be taken when opening a package + * to another module as such defined classes have the same full privilege + * access as other members in {@code M2}. * *

Cross-module access checks

*