211 /** 212 * Constructs a new named {@code URLClassLoader} for the specified URLs. 213 * The URLs will be searched in the order specified for classes 214 * and resources after first searching in the specified parent class loader. 215 * Any URL that ends with a '/' is assumed to refer to a directory. 216 * Otherwise, the URL is assumed to refer to a JAR file which will be 217 * downloaded and opened as needed. 218 * 219 * @param name class loader name; or {@code null} if not named 220 * @param urls the URLs from which to load classes and resources 221 * @param parent the parent class loader for delegation 222 * 223 * @throws IllegalArgumentException if the given name is empty. 224 * @throws NullPointerException if {@code urls} is {@code null}. 225 * 226 * @throws SecurityException if a security manager exists and its 227 * {@link SecurityManager#checkCreateClassLoader()} method doesn't 228 * allow creation of a class loader. 229 * 230 * @since 9 231 */ 232 public URLClassLoader(String name, 233 URL[] urls, 234 ClassLoader parent) { 235 super(name, parent); 236 // this is to make the stack depth consistent with 1.1 237 SecurityManager security = System.getSecurityManager(); 238 if (security != null) { 239 security.checkCreateClassLoader(); 240 } 241 this.acc = AccessController.getContext(); 242 this.ucp = new URLClassPath(urls, acc); 243 } 244 245 /** 246 * Constructs a new named {@code URLClassLoader} for the specified URLs, 247 * parent class loader, and URLStreamHandlerFactory. 248 * The parent argument will be used as the parent class loader for delegation. 249 * The factory argument will be used as the stream handler factory to 250 * obtain protocol handlers when creating new jar URLs. 251 * 252 * @param name class loader name; or {@code null} if not named 253 * @param urls the URLs from which to load classes and resources 254 * @param parent the parent class loader for delegation 255 * @param factory the URLStreamHandlerFactory to use when creating URLs 256 * 257 * @throws IllegalArgumentException if the given name is empty. 258 * @throws NullPointerException if {@code urls} is {@code null}. 259 * 260 * @throws SecurityException if a security manager exists and its 261 * {@code checkCreateClassLoader} method doesn't allow 262 * creation of a class loader. 263 * 264 * @since 9 265 */ 266 public URLClassLoader(String name, URL[] urls, ClassLoader parent, 267 URLStreamHandlerFactory factory) { 268 super(name, parent); 269 // this is to make the stack depth consistent with 1.1 270 SecurityManager security = System.getSecurityManager(); 271 if (security != null) { 272 security.checkCreateClassLoader(); 273 } 274 this.acc = AccessController.getContext(); 275 this.ucp = new URLClassPath(urls, factory, acc); 276 } 277 278 /* A map (used as a set) to keep track of closeable local resources 279 * (either JarFiles or FileInputStreams). We don't care about 280 * Http resources since they don't need to be closed. 281 * 282 * If the resource is coming from a jar file 283 * we keep a (weak) reference to the JarFile object which can 284 * be closed if URLClassLoader.close() called. Due to jar file 541 CodeSource cs = new CodeSource(url, signers); 542 PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0); 543 return defineClass(name, b, 0, b.length, cs); 544 } 545 } 546 547 /** 548 * Defines a new package by name in this {@code URLClassLoader}. 549 * The attributes contained in the specified {@code Manifest} 550 * will be used to obtain package version and sealing information. 551 * For sealed packages, the additional URL specifies the code source URL 552 * from which the package was loaded. 553 * 554 * @param name the package name 555 * @param man the {@code Manifest} containing package version and sealing 556 * information 557 * @param url the code source url for the package, or null if none 558 * @throws IllegalArgumentException if the package name is 559 * already defined by this class loader 560 * @return the newly defined {@code Package} object 561 */ 562 protected Package definePackage(String name, Manifest man, URL url) { 563 String path = name.replace('.', '/').concat("/"); 564 String specTitle = null, specVersion = null, specVendor = null; 565 String implTitle = null, implVersion = null, implVendor = null; 566 String sealed = null; 567 URL sealBase = null; 568 569 Attributes attr = man.getAttributes(path); 570 if (attr != null) { 571 specTitle = attr.getValue(Name.SPECIFICATION_TITLE); 572 specVersion = attr.getValue(Name.SPECIFICATION_VERSION); 573 specVendor = attr.getValue(Name.SPECIFICATION_VENDOR); 574 implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE); 575 implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION); 576 implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR); 577 sealed = attr.getValue(Name.SEALED); 578 } 579 attr = man.getMainAttributes(); 580 if (attr != null) { | 211 /** 212 * Constructs a new named {@code URLClassLoader} for the specified URLs. 213 * The URLs will be searched in the order specified for classes 214 * and resources after first searching in the specified parent class loader. 215 * Any URL that ends with a '/' is assumed to refer to a directory. 216 * Otherwise, the URL is assumed to refer to a JAR file which will be 217 * downloaded and opened as needed. 218 * 219 * @param name class loader name; or {@code null} if not named 220 * @param urls the URLs from which to load classes and resources 221 * @param parent the parent class loader for delegation 222 * 223 * @throws IllegalArgumentException if the given name is empty. 224 * @throws NullPointerException if {@code urls} is {@code null}. 225 * 226 * @throws SecurityException if a security manager exists and its 227 * {@link SecurityManager#checkCreateClassLoader()} method doesn't 228 * allow creation of a class loader. 229 * 230 * @since 9 231 * @spec JPMS 232 */ 233 public URLClassLoader(String name, 234 URL[] urls, 235 ClassLoader parent) { 236 super(name, parent); 237 // this is to make the stack depth consistent with 1.1 238 SecurityManager security = System.getSecurityManager(); 239 if (security != null) { 240 security.checkCreateClassLoader(); 241 } 242 this.acc = AccessController.getContext(); 243 this.ucp = new URLClassPath(urls, acc); 244 } 245 246 /** 247 * Constructs a new named {@code URLClassLoader} for the specified URLs, 248 * parent class loader, and URLStreamHandlerFactory. 249 * The parent argument will be used as the parent class loader for delegation. 250 * The factory argument will be used as the stream handler factory to 251 * obtain protocol handlers when creating new jar URLs. 252 * 253 * @param name class loader name; or {@code null} if not named 254 * @param urls the URLs from which to load classes and resources 255 * @param parent the parent class loader for delegation 256 * @param factory the URLStreamHandlerFactory to use when creating URLs 257 * 258 * @throws IllegalArgumentException if the given name is empty. 259 * @throws NullPointerException if {@code urls} is {@code null}. 260 * 261 * @throws SecurityException if a security manager exists and its 262 * {@code checkCreateClassLoader} method doesn't allow 263 * creation of a class loader. 264 * 265 * @since 9 266 * @spec JPMS 267 */ 268 public URLClassLoader(String name, URL[] urls, ClassLoader parent, 269 URLStreamHandlerFactory factory) { 270 super(name, parent); 271 // this is to make the stack depth consistent with 1.1 272 SecurityManager security = System.getSecurityManager(); 273 if (security != null) { 274 security.checkCreateClassLoader(); 275 } 276 this.acc = AccessController.getContext(); 277 this.ucp = new URLClassPath(urls, factory, acc); 278 } 279 280 /* A map (used as a set) to keep track of closeable local resources 281 * (either JarFiles or FileInputStreams). We don't care about 282 * Http resources since they don't need to be closed. 283 * 284 * If the resource is coming from a jar file 285 * we keep a (weak) reference to the JarFile object which can 286 * be closed if URLClassLoader.close() called. Due to jar file 543 CodeSource cs = new CodeSource(url, signers); 544 PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0); 545 return defineClass(name, b, 0, b.length, cs); 546 } 547 } 548 549 /** 550 * Defines a new package by name in this {@code URLClassLoader}. 551 * The attributes contained in the specified {@code Manifest} 552 * will be used to obtain package version and sealing information. 553 * For sealed packages, the additional URL specifies the code source URL 554 * from which the package was loaded. 555 * 556 * @param name the package name 557 * @param man the {@code Manifest} containing package version and sealing 558 * information 559 * @param url the code source url for the package, or null if none 560 * @throws IllegalArgumentException if the package name is 561 * already defined by this class loader 562 * @return the newly defined {@code Package} object 563 * 564 * @revised 9 565 * @spec JPMS 566 */ 567 protected Package definePackage(String name, Manifest man, URL url) { 568 String path = name.replace('.', '/').concat("/"); 569 String specTitle = null, specVersion = null, specVendor = null; 570 String implTitle = null, implVersion = null, implVendor = null; 571 String sealed = null; 572 URL sealBase = null; 573 574 Attributes attr = man.getAttributes(path); 575 if (attr != null) { 576 specTitle = attr.getValue(Name.SPECIFICATION_TITLE); 577 specVersion = attr.getValue(Name.SPECIFICATION_VERSION); 578 specVendor = attr.getValue(Name.SPECIFICATION_VENDOR); 579 implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE); 580 implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION); 581 implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR); 582 sealed = attr.getValue(Name.SEALED); 583 } 584 attr = man.getMainAttributes(); 585 if (attr != null) { |