< prev index next >

src/java.base/share/classes/java/lang/invoke/MethodHandles.java

Print this page
rev 13806 : 8150782: findClass / accessClass throw unexpected exceptions

*** 97,113 **** * It can only be used to create method handles to * publicly accessible fields and methods. * <p> * As a matter of pure convention, the {@linkplain Lookup#lookupClass lookup class} * of this lookup object will be {@link java.lang.Object}. * * <p style="font-size:smaller;"> * <em>Discussion:</em> * The lookup class can be changed to any other class {@code C} using an expression of the form * {@link Lookup#in publicLookup().in(C.class)}. * Since all classes have equal access to public names, ! * such a change would confer no new access rights. * A public lookup object is always subject to * <a href="MethodHandles.Lookup.html#secmgr">security manager checks</a>. * Also, it cannot access * <a href="MethodHandles.Lookup.html#callsens">caller sensitive methods</a>. * @return a lookup object which is trusted minimally --- 97,116 ---- * It can only be used to create method handles to * publicly accessible fields and methods. * <p> * As a matter of pure convention, the {@linkplain Lookup#lookupClass lookup class} * of this lookup object will be {@link java.lang.Object}. + * Consequently, the lookup context of this lookup object will be the bootstrap + * class loader, which means it cannot find or access user classes. * * <p style="font-size:smaller;"> * <em>Discussion:</em> * The lookup class can be changed to any other class {@code C} using an expression of the form * {@link Lookup#in publicLookup().in(C.class)}. * Since all classes have equal access to public names, ! * such a change would confer no new access rights, ! * but may change the lookup context by virtue of changing the class loader. * A public lookup object is always subject to * <a href="MethodHandles.Lookup.html#secmgr">security manager checks</a>. * Also, it cannot access * <a href="MethodHandles.Lookup.html#callsens">caller sensitive methods</a>. * @return a lookup object which is trusted minimally
*** 627,636 **** --- 630,641 ---- * The resulting object will report the specified * class as its own {@link #lookupClass lookupClass}. * <p> * However, the resulting {@code Lookup} object is guaranteed * to have no more access capabilities than the original. + * Access capabilities are determined by the lookup class' class loader, + * which may change due to this operation. * In particular, access capabilities can be lost as follows:<ul> * <li>If the new lookup class differs from the old one, * protected members will not be accessible by virtue of inheritance. * (Protected members may continue to be accessible because of package sharing.) * <li>If the new lookup class is in a different package
*** 937,946 **** --- 942,953 ---- } /** * Looks up a class by name from the lookup context defined by this {@code Lookup} object. The static * initializer of the class is not run. + * <p> + * The lookup context is determined by the class loader of the {@link #lookupClass()}. * * @param targetName the fully qualified name of the class to be looked up. * @return the requested class. * @exception SecurityException if a security manager is present and it * <a href="MethodHandles.Lookup.html#secmgr">refuses access</a>
*** 958,967 **** --- 965,976 ---- } /** * Determines if a class can be accessed from the lookup context defined by this {@code Lookup} object. The * static initializer of the class is not run. + * <p> + * The lookup context is determined by the class loader of the {@link #lookupClass()}. * * @param targetClass the class to be access-checked * * @return the class that has been access-checked *
< prev index next >