Program: 78530
Project: 78530
Buggy source:
/** 
 * Creates a new layer by defining the modules in the given   {@code Configuration} to the Java virtual machine. This method creates oneclass loader and defines all modules to that class loader. <p> The class loader created by this method implements <em>direct delegation</em> when loading types from modules. When its  {@link ClassLoader#loadClass(String,boolean) loadClass} method is invoked toload a class then it uses the package name of the class to map it to a module. This may be a module in this layer and hence defined to the same class loader. It may be a package in a module in a parent layer that is exported to one or more of the modules in this layer. The class loader delegates to the class loader of the module, throwing  {@code ClassNotFoundException} if not found by that class loader.When  {@code loadClass} is invoked to load classes that do not map to amodule then it delegates to the parent class loader. </p> <p> Attempting to create a layer with all modules defined to the same class loader can fail for the following reasons: <ul> <li><p> <em>Overlapping packages</em>: Two or more modules in the configuration have the same package. </p></li> <li><p> <em>Split delegation</em>: The resulting class loader would need to delegate to more than one class loader in order to load types in a specific package. </p></li> </ul> <p> If there is a security manager then the class loader created by this method will load classes and resources with privileges that are restricted by the calling context of this method. </p>
 * @param cf The configuration for the layer
 * @param parentLayers The list parent layers in search order
 * @param parentLoader The parent class loader for the class loader created by this method; may be  {@code null} for the bootstrap class loader
 * @return A controller that controls the newly created layer
 * @throws IllegalArgumentException If the parent configurations do not match the configuration of the parent layers, including order
 * @throws LayerInstantiationException If all modules cannot be defined to the same class loader for any of the reasons listed above or the layer cannot be created because the configuration contains a module named " {@code java.base}" or a module with a package name starting with "  {@code java.}"
 * @throws SecurityException If  {@code RuntimePermission("createClassLoader")} or{@code RuntimePermission("getClassLoader")} is denied bythe security manager
 * @see #findLoader
 */
public static Controller defineModulesWithOneLoader(Configuration cf,List<Layer> parentLayers,ClassLoader parentLoader){
  List<Layer> parents=new ArrayList<>(parentLayers);
  checkConfiguration(cf,parents);
  checkCreateClassLoaderPermission();
  checkGetClassLoaderPermission();
  try {
    Loader loader=new Loader(cf.modules(),parentLoader);
    loader.initRemotePackageMap(cf,parents);
    Layer layer=new Layer(cf,parents,mn -> loader);
    return new Controller(layer);
  }
 catch (  IllegalArgumentException e) {
    throw new LayerInstantiationException(e.getMessage());
  }
}

Fixed version (ground truth):
/** 
 * Creates a new layer by defining the modules in the given   {@code Configuration} to the Java virtual machine. This method creates oneclass loader and defines all modules to that class loader. <p> The class loader created by this method implements <em>direct delegation</em> when loading types from modules. When its  {@link ClassLoader#loadClass(String,boolean) loadClass} method is invoked toload a class then it uses the package name of the class to map it to a module. This may be a module in this layer and hence defined to the same class loader. It may be a package in a module in a parent layer that is exported to one or more of the modules in this layer. The class loader delegates to the class loader of the module, throwing  {@code ClassNotFoundException} if not found by that class loader.When  {@code loadClass} is invoked to load classes that do not map to amodule then it delegates to the parent class loader. </p> <p> Attempting to create a layer with all modules defined to the same class loader can fail for the following reasons: <ul> <li><p> <em>Overlapping packages</em>: Two or more modules in the configuration have the same package. </p></li> <li><p> <em>Split delegation</em>: The resulting class loader would need to delegate to more than one class loader in order to load types in a specific package. </p></li> </ul> <p> If there is a security manager then the class loader created by this method will load classes and resources with privileges that are restricted by the calling context of this method. </p>
 * @param cf The configuration for the layer
 * @param parentLayers The list parent layers in search order
 * @param parentLoader The parent class loader for the class loader created by this method; may be  {@code null} for the bootstrap class loader
 * @return A controller that controls the newly created layer
 * @throws IllegalArgumentException If the parent configurations do not match the configuration of the parent layers, including order
 * @throws LayerInstantiationException If all modules cannot be defined to the same class loader for any of the reasons listed above or the layer cannot be created because the configuration contains a module named " {@code java.base}" or a module with a package name starting with "  {@code java.}"
 * @throws SecurityException If  {@code RuntimePermission("createClassLoader")} or{@code RuntimePermission("getClassLoader")} is denied bythe security manager
 * @see #findLoader
 */
public static Controller defineModulesWithOneLoader(Configuration cf,List<Layer> parentLayers,ClassLoader parentLoader){
  List<Layer> parents=new ArrayList<>(parentLayers);
  checkConfiguration(cf,parents);
  checkCreateClassLoaderPermission();
  checkGetClassLoaderPermission();
  try {
    Loader loader=new Loader(cf.modules(),parentLoader);
    loader.initRemotePackageMap(cf,parents);
    Layer layer=new Layer(cf,parents,mn -> loader);
    return new Controller(layer);
  }
 catch (  IllegalArgumentException|IllegalStateException e) {
    throw new LayerInstantiationException(e.getMessage());
  }
}