Program: 29170
Project: 29170
Buggy source:
/** 
 * Specific stages of the Weld bootstrapping process will execute across different stages of the deployment process.  Weld deployment will happen when the load phase of the  deployment process is complete.  When all modules have been loaded, a deployment  graph is produced defining the accessiblity relationships between  <code>BeanDeploymentArchive</code>s.
 */
public void event(Event event){
  if (event.is(org.glassfish.internal.deployment.Deployment.APPLICATION_LOADED)) {
    ApplicationInfo appInfo=(ApplicationInfo)event.hook();
    WeldBootstrap bootstrap=appInfo.getTransientAppMetaData(WELD_BOOTSTRAP,WeldBootstrap.class);
    if (bootstrap != null) {
      DeploymentImpl deploymentImpl=appInfo.getTransientAppMetaData(WELD_DEPLOYMENT,DeploymentImpl.class);
      List<BeanDeploymentArchive> archives=deploymentImpl.getBeanDeploymentArchives();
      for (      BeanDeploymentArchive archive : archives) {
        ResourceLoaderImpl loader=new ResourceLoaderImpl(((BeanDeploymentArchiveImpl)archive).getModuleClassLoaderForBDA());
        archive.getServices().add(ResourceLoader.class,loader);
      }
      deploymentImpl.buildDeploymentGraph();
      if (_logger.isLoggable(Level.FINE)) {
        _logger.fine(deploymentImpl.toString());
      }
      ClassLoader oldTCL=Thread.currentThread().getContextClassLoader();
      try {
        bootstrap.startContainer(Environments.SERVLET,deploymentImpl);
        bootstrap.startInitialization();
        fireProcessInjectionTargetEvents(bootstrap,deploymentImpl);
        bootstrap.deployBeans();
      }
 catch (      Throwable t) {
        DeploymentException de=new DeploymentException(t.getMessage());
        de.initCause(t);
        throw (de);
      }
 finally {
        Thread.currentThread().setContextClassLoader(oldTCL);
      }
    }
  }
 else   if (event.is(org.glassfish.internal.deployment.Deployment.APPLICATION_STARTED)) {
    ApplicationInfo appInfo=(ApplicationInfo)event.hook();
    WeldBootstrap bootstrap=appInfo.getTransientAppMetaData(WELD_BOOTSTRAP,WeldBootstrap.class);
    if (bootstrap != null) {
      try {
        bootstrap.validateBeans();
        bootstrap.endInitialization();
      }
 catch (      Throwable t) {
        DeploymentException de=new DeploymentException(t.getMessage());
        de.initCause(t);
        throw (de);
      }
    }
  }
 else   if (event.is(org.glassfish.internal.deployment.Deployment.APPLICATION_STOPPED) || event.is(org.glassfish.internal.deployment.Deployment.APPLICATION_UNLOADED)) {
    ApplicationInfo appInfo=(ApplicationInfo)event.hook();
    Application app=appInfo.getMetaData(Application.class);
    if (app != null) {
      for (      BundleDescriptor next : app.getBundleDescriptors()) {
        if (next instanceof EjbBundleDescriptor || next instanceof WebBundleDescriptor) {
          bundleToBeanDeploymentArchive.remove(next);
        }
      }
      appToBootstrap.remove(app);
    }
    String shutdown=appInfo.getTransientAppMetaData(WELD_SHUTDOWN,String.class);
    if (Boolean.valueOf(shutdown) == Boolean.TRUE) {
      return;
    }
    WeldBootstrap bootstrap=appInfo.getTransientAppMetaData(WELD_BOOTSTRAP,WeldBootstrap.class);
    if (bootstrap != null) {
      try {
        bootstrap.shutdown();
      }
 catch (      Exception e) {
        _logger.log(Level.WARNING,"String_Node_Str",e);
      }
      appInfo.addTransientAppMetaData(WELD_SHUTDOWN,"String_Node_Str");
    }
    DeploymentImpl deploymentImpl=appInfo.getTransientAppMetaData(WELD_DEPLOYMENT,DeploymentImpl.class);
    if (deploymentImpl != null) {
      deploymentImpl.cleanup();
    }
  }
}

Fixed version (ground truth):
/** 
 * Specific stages of the Weld bootstrapping process will execute across different stages of the deployment process.  Weld deployment will happen when the load phase of the  deployment process is complete.  When all modules have been loaded, a deployment  graph is produced defining the accessiblity relationships between  <code>BeanDeploymentArchive</code>s.
 */
public void event(Event event){
  if (event.is(org.glassfish.internal.deployment.Deployment.APPLICATION_LOADED)) {
    ApplicationInfo appInfo=(ApplicationInfo)event.hook();
    WeldBootstrap bootstrap=appInfo.getTransientAppMetaData(WELD_BOOTSTRAP,WeldBootstrap.class);
    if (bootstrap != null) {
      DeploymentImpl deploymentImpl=appInfo.getTransientAppMetaData(WELD_DEPLOYMENT,DeploymentImpl.class);
      List<BeanDeploymentArchive> archives=deploymentImpl.getBeanDeploymentArchives();
      for (      BeanDeploymentArchive archive : archives) {
        ResourceLoaderImpl loader=new ResourceLoaderImpl(((BeanDeploymentArchiveImpl)archive).getModuleClassLoaderForBDA());
        archive.getServices().add(ResourceLoader.class,loader);
      }
      deploymentImpl.buildDeploymentGraph();
      if (_logger.isLoggable(Level.FINE)) {
        _logger.fine(deploymentImpl.toString());
      }
      ClassLoader oldTCL=Thread.currentThread().getContextClassLoader();
      try {
        bootstrap.startContainer(Environments.SERVLET,deploymentImpl);
        bootstrap.startInitialization();
        fireProcessInjectionTargetEvents(bootstrap,deploymentImpl);
        bootstrap.deployBeans();
      }
 catch (      Throwable t) {
        DeploymentException de=new DeploymentException(t.getMessage());
        de.initCause(t);
        throw (de);
      }
 finally {
        Thread.currentThread().setContextClassLoader(oldTCL);
      }
    }
  }
 else   if (event.is(org.glassfish.internal.deployment.Deployment.APPLICATION_STARTED)) {
    ApplicationInfo appInfo=(ApplicationInfo)event.hook();
    WeldBootstrap bootstrap=appInfo.getTransientAppMetaData(WELD_BOOTSTRAP,WeldBootstrap.class);
    if (bootstrap != null) {
      try {
        bootstrap.validateBeans();
        bootstrap.endInitialization();
      }
 catch (      Throwable t) {
        DeploymentException de=new DeploymentException(t.getMessage());
        de.initCause(t);
        throw (de);
      }
    }
  }
 else   if (event.is(org.glassfish.internal.deployment.Deployment.APPLICATION_STOPPED) || event.is(org.glassfish.internal.deployment.Deployment.APPLICATION_UNLOADED)) {
    ApplicationInfo appInfo=(ApplicationInfo)event.hook();
    Application app=appInfo.getMetaData(Application.class);
    if (app != null) {
      for (      BundleDescriptor next : app.getBundleDescriptors()) {
        if (next instanceof EjbBundleDescriptor || next instanceof WebBundleDescriptor) {
          bundleToBeanDeploymentArchive.remove(next);
        }
      }
      appToBootstrap.remove(app);
    }
    String shutdown=appInfo.getTransientAppMetaData(WELD_SHUTDOWN,String.class);
    if (Boolean.valueOf(shutdown).equals(Boolean.TRUE)) {
      return;
    }
    WeldBootstrap bootstrap=appInfo.getTransientAppMetaData(WELD_BOOTSTRAP,WeldBootstrap.class);
    if (bootstrap != null) {
      try {
        bootstrap.shutdown();
      }
 catch (      Exception e) {
        _logger.log(Level.WARNING,"String_Node_Str",e);
      }
      appInfo.addTransientAppMetaData(WELD_SHUTDOWN,"String_Node_Str");
    }
    DeploymentImpl deploymentImpl=appInfo.getTransientAppMetaData(WELD_DEPLOYMENT,DeploymentImpl.class);
    if (deploymentImpl != null) {
      deploymentImpl.cleanup();
    }
  }
}