< prev index next >

src/java.base/share/classes/java/lang/ClassLoader.java

Print this page




1100                 byte[] tb = new byte[len];
1101                 b.get(tb);  // get bytes out of byte buffer.
1102                 return defineClass(name, tb, 0, len, protectionDomain);
1103             }
1104         }
1105 
1106         protectionDomain = preDefineClass(name, protectionDomain);
1107         String source = defineClassSourceLocation(protectionDomain);
1108         Class<?> c = defineClass2(this, name, b, b.position(), len, protectionDomain, source);
1109         postDefineClass(c, protectionDomain);
1110         return c;
1111     }
1112 
1113     static native Class<?> defineClass1(ClassLoader loader, String name, byte[] b, int off, int len,
1114                                         ProtectionDomain pd, String source);
1115 
1116     static native Class<?> defineClass2(ClassLoader loader, String name, java.nio.ByteBuffer b,
1117                                         int off, int len, ProtectionDomain pd,
1118                                         String source);
1119 





















1120     // true if the name is null or has the potential to be a valid binary name
1121     private boolean checkName(String name) {
1122         if ((name == null) || (name.isEmpty()))
1123             return true;
1124         if ((name.indexOf('/') != -1) || (name.charAt(0) == '['))
1125             return false;
1126         return true;
1127     }
1128 
1129     private void checkCerts(String name, CodeSource cs) {
1130         int i = name.lastIndexOf('.');
1131         String pname = (i == -1) ? "" : name.substring(0, i);
1132 
1133         Certificate[] certs = null;
1134         if (cs != null) {
1135             certs = cs.getCertificates();
1136         }
1137         Certificate[] pcerts = null;
1138         if (parallelLockMap == null) {
1139             synchronized (this) {




1100                 byte[] tb = new byte[len];
1101                 b.get(tb);  // get bytes out of byte buffer.
1102                 return defineClass(name, tb, 0, len, protectionDomain);
1103             }
1104         }
1105 
1106         protectionDomain = preDefineClass(name, protectionDomain);
1107         String source = defineClassSourceLocation(protectionDomain);
1108         Class<?> c = defineClass2(this, name, b, b.position(), len, protectionDomain, source);
1109         postDefineClass(c, protectionDomain);
1110         return c;
1111     }
1112 
1113     static native Class<?> defineClass1(ClassLoader loader, String name, byte[] b, int off, int len,
1114                                         ProtectionDomain pd, String source);
1115 
1116     static native Class<?> defineClass2(ClassLoader loader, String name, java.nio.ByteBuffer b,
1117                                         int off, int len, ProtectionDomain pd,
1118                                         String source);
1119 
1120     /**
1121      * Defines a class of the given flags via Lookup.defineClass.
1122      *
1123      * @param loader the defining loader
1124      * @param lookup nest host of the Class to be defined
1125      * @param name the binary name or {@code null} if not findable
1126      * @param b class bytes
1127      * @param off the start offset in {@code b} of the class bytes
1128      * @param len the length of the class bytes
1129      * @param pd protection domain
1130      * @param flags flags
1131      * @param classData class data
1132      */
1133     static native Class<?> defineClass0(ClassLoader loader,
1134                                         Class<?> lookup,
1135                                         String name,
1136                                         byte[] b, int off, int len,
1137                                         ProtectionDomain pd,
1138                                         int flags,
1139                                         Object classData);
1140 
1141     // true if the name is null or has the potential to be a valid binary name
1142     private boolean checkName(String name) {
1143         if ((name == null) || (name.isEmpty()))
1144             return true;
1145         if ((name.indexOf('/') != -1) || (name.charAt(0) == '['))
1146             return false;
1147         return true;
1148     }
1149 
1150     private void checkCerts(String name, CodeSource cs) {
1151         int i = name.lastIndexOf('.');
1152         String pname = (i == -1) ? "" : name.substring(0, i);
1153 
1154         Certificate[] certs = null;
1155         if (cs != null) {
1156             certs = cs.getCertificates();
1157         }
1158         Certificate[] pcerts = null;
1159         if (parallelLockMap == null) {
1160             synchronized (this) {


< prev index next >