< prev index next >

src/java.base/share/classes/java/lang/reflect/Layer.java

Print this page
rev 14279 : [mq]: 8140281-deprecation-optional.get


 345         // the overhead at startup to a minimum
 346         if (boot() == null) {
 347             checkBootModulesForDuplicatePkgs(cf);
 348         } else {
 349             checkForDuplicatePkgs(cf, clf);
 350         }
 351 
 352         try {
 353             return new Layer(cf, this, clf);
 354         } catch (IllegalArgumentException iae) {
 355             // IAE is thrown by VM when defining the module fails
 356             throw new LayerInstantiationException(iae.getMessage());
 357         }
 358     }
 359 
 360 
 361     private void checkConfiguration(Configuration cf) {
 362         Objects.requireNonNull(cf);
 363 
 364         Optional<Configuration> oparent = cf.parent();
 365         if (!oparent.isPresent() || oparent.get() != this.configuration()) {
 366             throw new IllegalArgumentException(
 367                     "Parent of configuration != configuration of this Layer");
 368         }
 369     }
 370 
 371     private static void checkCreateClassLoaderPermission() {
 372         SecurityManager sm = System.getSecurityManager();
 373         if (sm != null)
 374             sm.checkPermission(SecurityConstants.CREATE_CLASSLOADER_PERMISSION);
 375     }
 376 
 377     private static void checkGetClassLoaderPermission() {
 378         SecurityManager sm = System.getSecurityManager();
 379         if (sm != null)
 380             sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
 381     }
 382 
 383     /**
 384      * Checks a configuration for the boot Layer to ensure that no two modules
 385      * have the same package.


 503      *
 504      * @apiNote This method does not return an {@code Optional<ClassLoader>}
 505      * because `null` must be used to represent the bootstrap class loader.
 506      *
 507      * @param  name
 508      *         The name of the module to find
 509      *
 510      * @return The ClassLoader that the module is defined to
 511      *
 512      * @throws IllegalArgumentException if a module of the given name is not
 513      *         defined in this layer or any parent of this layer
 514      *
 515      * @throws SecurityException if denied by the security manager
 516      */
 517     public ClassLoader findLoader(String name) {
 518         Module m = nameToModule.get(Objects.requireNonNull(name));
 519         if (m != null)
 520             return m.getClassLoader();
 521         Optional<Layer> ol = parent();
 522         if (ol.isPresent())
 523             return ol.get().findLoader(name);
 524         throw new IllegalArgumentException("Module " + name
 525                                            + " not known to this layer");
 526     }
 527 
 528 
 529     /**
 530      * Returns the <em>empty</em> layer. There are no modules in the empty
 531      * layer. It has no parent.
 532      *
 533      * @return The empty layer
 534      */
 535     public static Layer empty() {
 536         return EMPTY_LAYER;
 537     }
 538 
 539 
 540     /**
 541      * Returns the boot layer. The boot layer contains at least one module,
 542      * {@code java.base}. Its parent is the {@link #empty() empty} layer.
 543      *


 345         // the overhead at startup to a minimum
 346         if (boot() == null) {
 347             checkBootModulesForDuplicatePkgs(cf);
 348         } else {
 349             checkForDuplicatePkgs(cf, clf);
 350         }
 351 
 352         try {
 353             return new Layer(cf, this, clf);
 354         } catch (IllegalArgumentException iae) {
 355             // IAE is thrown by VM when defining the module fails
 356             throw new LayerInstantiationException(iae.getMessage());
 357         }
 358     }
 359 
 360 
 361     private void checkConfiguration(Configuration cf) {
 362         Objects.requireNonNull(cf);
 363 
 364         Optional<Configuration> oparent = cf.parent();
 365         if (!oparent.isPresent() || oparent.getWhenPresent() != this.configuration()) {
 366             throw new IllegalArgumentException(
 367                     "Parent of configuration != configuration of this Layer");
 368         }
 369     }
 370 
 371     private static void checkCreateClassLoaderPermission() {
 372         SecurityManager sm = System.getSecurityManager();
 373         if (sm != null)
 374             sm.checkPermission(SecurityConstants.CREATE_CLASSLOADER_PERMISSION);
 375     }
 376 
 377     private static void checkGetClassLoaderPermission() {
 378         SecurityManager sm = System.getSecurityManager();
 379         if (sm != null)
 380             sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
 381     }
 382 
 383     /**
 384      * Checks a configuration for the boot Layer to ensure that no two modules
 385      * have the same package.


 503      *
 504      * @apiNote This method does not return an {@code Optional<ClassLoader>}
 505      * because `null` must be used to represent the bootstrap class loader.
 506      *
 507      * @param  name
 508      *         The name of the module to find
 509      *
 510      * @return The ClassLoader that the module is defined to
 511      *
 512      * @throws IllegalArgumentException if a module of the given name is not
 513      *         defined in this layer or any parent of this layer
 514      *
 515      * @throws SecurityException if denied by the security manager
 516      */
 517     public ClassLoader findLoader(String name) {
 518         Module m = nameToModule.get(Objects.requireNonNull(name));
 519         if (m != null)
 520             return m.getClassLoader();
 521         Optional<Layer> ol = parent();
 522         if (ol.isPresent())
 523             return ol.getWhenPresent().findLoader(name);
 524         throw new IllegalArgumentException("Module " + name
 525                                            + " not known to this layer");
 526     }
 527 
 528 
 529     /**
 530      * Returns the <em>empty</em> layer. There are no modules in the empty
 531      * layer. It has no parent.
 532      *
 533      * @return The empty layer
 534      */
 535     public static Layer empty() {
 536         return EMPTY_LAYER;
 537     }
 538 
 539 
 540     /**
 541      * Returns the boot layer. The boot layer contains at least one module,
 542      * {@code java.base}. Its parent is the {@link #empty() empty} layer.
 543      *
< prev index next >