832 * Ensure the given module can access the given class.
833 */
834 private static void ensureAccess(Module target, Class<?> c) {
835 Module m = c.getModule();
836 // add read edge and qualified export for the target module to access
837 if (!target.canRead(m)) {
838 Modules.addReads(target, m);
839 }
840 String pn = c.getPackageName();
841 if (!m.isExported(pn, target)) {
842 Modules.addExports(m, pn, target);
843 }
844 }
845
846 /*
847 * Ensure the given class is visible to the class loader.
848 */
849 private static void ensureVisible(ClassLoader ld, Class<?> c) {
850 Class<?> type = null;
851 try {
852 type = Class.forName(c.getName(), false, ld);
853 } catch (ClassNotFoundException e) {
854 }
855 // use box type to do visibility check
856 if (type != c.asBoxType()) {
857 throw new IllegalArgumentException(c.getName() +
858 " referenced from a method is not visible from class loader");
859 }
860 }
861
862 private static Class<?> getElementType(Class<?> type) {
863 Class<?> e = type;
864 while (e.isArray()) {
865 e = e.getComponentType();
866 }
867 return e;
868 }
869
870 private static final ClassLoaderValue<Module> dynProxyModules =
871 new ClassLoaderValue<>();
872 private static final AtomicInteger counter = new AtomicInteger();
873
874 /*
875 * Define a dynamic module for the generated proxy classes in
876 * a non-exported package named com.sun.proxy.$MODULE.
|
832 * Ensure the given module can access the given class.
833 */
834 private static void ensureAccess(Module target, Class<?> c) {
835 Module m = c.getModule();
836 // add read edge and qualified export for the target module to access
837 if (!target.canRead(m)) {
838 Modules.addReads(target, m);
839 }
840 String pn = c.getPackageName();
841 if (!m.isExported(pn, target)) {
842 Modules.addExports(m, pn, target);
843 }
844 }
845
846 /*
847 * Ensure the given class is visible to the class loader.
848 */
849 private static void ensureVisible(ClassLoader ld, Class<?> c) {
850 Class<?> type = null;
851 try {
852 if (c.isInlineClass() && c.isNullableType()) c = c.asPrimaryType();
853 type = Class.forName(c.getName(), false, ld);
854 } catch (ClassNotFoundException e) {
855 }
856 if (type != c) {
857 throw new IllegalArgumentException(c.getName() +
858 " referenced from a method is not visible from class loader");
859 }
860 }
861
862 private static Class<?> getElementType(Class<?> type) {
863 Class<?> e = type;
864 while (e.isArray()) {
865 e = e.getComponentType();
866 }
867 return e;
868 }
869
870 private static final ClassLoaderValue<Module> dynProxyModules =
871 new ClassLoaderValue<>();
872 private static final AtomicInteger counter = new AtomicInteger();
873
874 /*
875 * Define a dynamic module for the generated proxy classes in
876 * a non-exported package named com.sun.proxy.$MODULE.
|