Program: 28138
Project: 28138
Buggy source:
private void populate(Collection<com.sun.enterprise.deployment.EjbDescriptor> ejbs,Application app){
  try {
    boolean webinfbda=false;
    boolean hasBeansXml=false;
    String beansXMLURL=null;
    if (archive.exists(WEB_INF_BEANS_XML)) {
      beansXMLURL=WEB_INF_BEANS_XML;
    }
    if (beansXMLURL == null && archive.exists(WEB_INF_CLASSES_META_INF_BEANS_XML)) {
      beansXMLURL=WEB_INF_CLASSES_META_INF_BEANS_XML;
    }
    if (beansXMLURL != null) {
      BeansXml beansXML=parseBeansXML(archive,beansXMLURL);
      BeanDiscoveryMode bdMode=beansXML.getBeanDiscoveryMode();
      if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
        webinfbda=true;
        hasBeansXml=!bdMode.equals(BeanDiscoveryMode.ANNOTATED);
        if (logger.isLoggable(FINE)) {
          logger.log(FINE,CDILoggerInfo.PROCESSING_BEANS_XML,new Object[]{archive.getURI(),WEB_INF_BEANS_XML,WEB_INF_CLASSES_META_INF_BEANS_XML});
        }
      }
 else {
        addBeansXMLURL(archive,beansXMLURL);
      }
    }
 else     if (archive.exists(WEB_INF_CLASSES)) {
      URI webinfclasses=new File(context.getSourceDir().getAbsolutePath(),WEB_INF_CLASSES).toURI();
      if (WeldUtils.isImplicitBeanArchive(context,webinfclasses)) {
        webinfbda=true;
        if (logger.isLoggable(FINE)) {
          logger.log(FINE,CDILoggerInfo.PROCESSING_CDI_ENABLED_ARCHIVE,new Object[]{archive.getURI()});
        }
      }
    }
    if (webinfbda) {
      bdaType=BDAType.WAR;
      Enumeration<String> entries=archive.entries();
      while (entries.hasMoreElements()) {
        String entry=entries.nextElement();
        if (legalClassName(entry)) {
          if (entry.contains(WEB_INF_CLASSES)) {
            entry=entry.substring(WEB_INF_CLASSES.length() + 1);
          }
          String className=filenameToClassname(entry);
          try {
            if (hasBeansXml || isCDIAnnotatedClass(className)) {
              beanClassNames.add(className);
              beanClasses.add(getClassLoader().loadClass(className));
            }
            moduleClassNames.add(className);
          }
 catch (          Throwable t) {
            if (logger.isLoggable(Level.WARNING)) {
              logger.log(Level.WARNING,CDILoggerInfo.ERROR_LOADING_BEAN_CLASS,new Object[]{className,t.toString()});
            }
          }
        }
 else         if (entry.endsWith(BEANS_XML_FILENAME)) {
          addBeansXMLURL(archive,entry);
        }
      }
      archive.close();
    }
    if (archive.exists(WEB_INF_LIB)) {
      if (logger.isLoggable(FINE)) {
        logger.log(FINE,CDILoggerInfo.PROCESSING_WEB_INF_LIB,new Object[]{archive.getURI()});
      }
      bdaType=BDAType.WAR;
      Enumeration<String> entries=archive.entries(WEB_INF_LIB);
      List<ReadableArchive> weblibJarsThatAreBeanArchives=new ArrayList<ReadableArchive>();
      while (entries.hasMoreElements()) {
        String entry=(String)entries.nextElement();
        if (entry.endsWith(JAR_SUFFIX) && entry.indexOf(SEPARATOR_CHAR,WEB_INF_LIB.length() + 1) == -1 && (app == null || DOLUtils.isScanningAllowed(app,entry))) {
          ReadableArchive weblibJarArchive=archive.getSubArchive(entry);
          if (weblibJarArchive.exists(META_INF_BEANS_XML)) {
            BeansXml beansXML=parseBeansXML(weblibJarArchive,META_INF_BEANS_XML);
            BeanDiscoveryMode bdMode=beansXML.getBeanDiscoveryMode();
            if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
              if (logger.isLoggable(FINE)) {
                logger.log(FINE,CDILoggerInfo.WEB_INF_LIB_CONSIDERING_BEAN_ARCHIVE,new Object[]{entry});
              }
              if (!bdMode.equals(BeanDiscoveryMode.ANNOTATED) || isImplicitBeanArchive(context,weblibJarArchive)) {
                weblibJarsThatAreBeanArchives.add(weblibJarArchive);
              }
            }
          }
 else {
            if (WeldUtils.isImplicitBeanArchive(context,weblibJarArchive)) {
              if (logger.isLoggable(FINE)) {
                logger.log(FINE,CDILoggerInfo.WEB_INF_LIB_CONSIDERING_BEAN_ARCHIVE,new Object[]{entry});
              }
              weblibJarsThatAreBeanArchives.add(weblibJarArchive);
            }
 else {
              if (logger.isLoggable(FINE)) {
                logger.log(FINE,CDILoggerInfo.WEB_INF_LIB_SKIPPING_BEAN_ARCHIVE,new Object[]{archive.getName()});
              }
            }
          }
        }
      }
      List<BeanDeploymentArchiveImpl> webLibBDAs=new ArrayList<BeanDeploymentArchiveImpl>();
      if (weblibJarsThatAreBeanArchives.size() > 0) {
        ListIterator<ReadableArchive> libJarIterator=weblibJarsThatAreBeanArchives.listIterator();
        while (libJarIterator.hasNext()) {
          ReadableArchive libJarArchive=(ReadableArchive)libJarIterator.next();
          BeanDeploymentArchiveImpl wlbda=new BeanDeploymentArchiveImpl(libJarArchive,ejbs,context,makeBdaId(friendlyId,bdaType,libJarArchive.getName()));
          this.beanDeploymentArchives.add(wlbda);
          webLibBDAs.add(wlbda);
        }
      }
      ensureWebLibJarVisibility(webLibBDAs);
    }
 else     if (archive.getName().endsWith(RAR_SUFFIX) || archive.getName().endsWith(EXPANDED_RAR_SUFFIX)) {
      bdaType=BDAType.RAR;
      collectRarInfo(archive);
    }
 else     if (archive.exists(META_INF_BEANS_XML)) {
      BeansXml beansXML=parseBeansXML(archive,META_INF_BEANS_XML);
      BeanDiscoveryMode bdMode=beansXML.getBeanDiscoveryMode();
      if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
        if (logger.isLoggable(FINE)) {
          logger.log(FINE,CDILoggerInfo.PROCESSING_BDA_JAR,new Object[]{archive.getURI()});
        }
        bdaType=BDAType.JAR;
        collectJarInfo(archive,true,!bdMode.equals(BeanDiscoveryMode.ANNOTATED));
      }
 else {
        addBeansXMLURL(archive,META_INF_BEANS_XML);
      }
    }
 else     if (WeldUtils.isImplicitBeanArchive(context,archive)) {
      if (logger.isLoggable(FINE)) {
        logger.log(FINE,CDILoggerInfo.PROCESSING_BECAUSE_SCOPE_ANNOTATION,new Object[]{archive.getURI()});
      }
      bdaType=BDAType.JAR;
      collectJarInfo(archive,true,false);
    }
  }
 catch (  IOException e) {
    logger.log(SEVERE,e.getLocalizedMessage(),e);
  }
catch (  ClassNotFoundException cne) {
    logger.log(SEVERE,cne.getLocalizedMessage(),cne);
  }
}

Fixed version (ground truth):
private void populate(Collection<com.sun.enterprise.deployment.EjbDescriptor> ejbs,Application app){
  try {
    boolean webinfbda=false;
    boolean hasBeansXml=false;
    String beansXMLURL=null;
    if (archive.exists(WEB_INF_BEANS_XML)) {
      beansXMLURL=WEB_INF_BEANS_XML;
    }
    if (beansXMLURL == null && archive.exists(WEB_INF_CLASSES_META_INF_BEANS_XML)) {
      beansXMLURL=WEB_INF_CLASSES_META_INF_BEANS_XML;
    }
    if (beansXMLURL != null) {
      BeansXml beansXML=parseBeansXML(archive,beansXMLURL);
      BeanDiscoveryMode bdMode=beansXML.getBeanDiscoveryMode();
      if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
        webinfbda=true;
        hasBeansXml=!bdMode.equals(BeanDiscoveryMode.ANNOTATED);
        if (logger.isLoggable(FINE)) {
          logger.log(FINE,CDILoggerInfo.PROCESSING_BEANS_XML,new Object[]{archive.getURI(),WEB_INF_BEANS_XML,WEB_INF_CLASSES_META_INF_BEANS_XML});
        }
      }
 else {
        addBeansXMLURL(archive,beansXMLURL);
      }
    }
 else     if (archive.exists(WEB_INF_CLASSES)) {
      URI webinfclasses=new File(context.getSourceDir().getAbsolutePath(),WEB_INF_CLASSES).toURI();
      if (WeldUtils.isImplicitBeanArchive(context,webinfclasses)) {
        webinfbda=true;
        if (logger.isLoggable(FINE)) {
          logger.log(FINE,CDILoggerInfo.PROCESSING_CDI_ENABLED_ARCHIVE,new Object[]{archive.getURI()});
        }
      }
    }
    if (webinfbda) {
      bdaType=BDAType.WAR;
      Enumeration<String> entries=archive.entries();
      while (entries.hasMoreElements()) {
        String entry=entries.nextElement();
        if (legalClassName(entry)) {
          if (entry.contains(WEB_INF_CLASSES)) {
            entry=entry.substring(WEB_INF_CLASSES.length() + 1);
          }
          String className=filenameToClassname(entry);
          try {
            if (hasBeansXml || isCDIAnnotatedClass(className)) {
              beanClassNames.add(className);
              beanClasses.add(getClassLoader().loadClass(className));
            }
            moduleClassNames.add(className);
          }
 catch (          Throwable t) {
            if (logger.isLoggable(Level.WARNING)) {
              logger.log(Level.WARNING,CDILoggerInfo.ERROR_LOADING_BEAN_CLASS,new Object[]{className,t.toString()});
            }
          }
        }
 else         if (entry.endsWith(BEANS_XML_FILENAME)) {
          addBeansXMLURL(archive,entry);
        }
      }
      archive.close();
    }
    if (archive.exists(WEB_INF_LIB)) {
      if (logger.isLoggable(FINE)) {
        logger.log(FINE,CDILoggerInfo.PROCESSING_WEB_INF_LIB,new Object[]{archive.getURI()});
      }
      bdaType=BDAType.WAR;
      Enumeration<String> entries=archive.entries(WEB_INF_LIB);
      List<ReadableArchive> weblibJarsThatAreBeanArchives=new ArrayList<ReadableArchive>();
      while (entries.hasMoreElements()) {
        String entry=(String)entries.nextElement();
        if (entry.endsWith(JAR_SUFFIX) && entry.indexOf(SEPARATOR_CHAR,WEB_INF_LIB.length() + 1) == -1 && (app == null || DOLUtils.isScanningAllowed(app,entry))) {
          ReadableArchive weblibJarArchive=archive.getSubArchive(entry);
          if (weblibJarArchive.exists(META_INF_BEANS_XML)) {
            BeansXml beansXML=parseBeansXML(weblibJarArchive,META_INF_BEANS_XML);
            BeanDiscoveryMode bdMode=beansXML.getBeanDiscoveryMode();
            if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
              if (logger.isLoggable(FINE)) {
                logger.log(FINE,CDILoggerInfo.WEB_INF_LIB_CONSIDERING_BEAN_ARCHIVE,new Object[]{entry});
              }
              weblibJarsThatAreBeanArchives.add(weblibJarArchive);
            }
          }
 else {
            if (WeldUtils.isImplicitBeanArchive(context,weblibJarArchive)) {
              if (logger.isLoggable(FINE)) {
                logger.log(FINE,CDILoggerInfo.WEB_INF_LIB_CONSIDERING_BEAN_ARCHIVE,new Object[]{entry});
              }
              weblibJarsThatAreBeanArchives.add(weblibJarArchive);
            }
 else {
              if (logger.isLoggable(FINE)) {
                logger.log(FINE,CDILoggerInfo.WEB_INF_LIB_SKIPPING_BEAN_ARCHIVE,new Object[]{archive.getName()});
              }
            }
          }
        }
      }
      List<BeanDeploymentArchiveImpl> webLibBDAs=new ArrayList<BeanDeploymentArchiveImpl>();
      if (weblibJarsThatAreBeanArchives.size() > 0) {
        ListIterator<ReadableArchive> libJarIterator=weblibJarsThatAreBeanArchives.listIterator();
        while (libJarIterator.hasNext()) {
          ReadableArchive libJarArchive=(ReadableArchive)libJarIterator.next();
          BeanDeploymentArchiveImpl wlbda=new BeanDeploymentArchiveImpl(libJarArchive,ejbs,context,makeBdaId(friendlyId,bdaType,libJarArchive.getName()));
          this.beanDeploymentArchives.add(wlbda);
          webLibBDAs.add(wlbda);
        }
      }
      ensureWebLibJarVisibility(webLibBDAs);
    }
 else     if (archive.getName().endsWith(RAR_SUFFIX) || archive.getName().endsWith(EXPANDED_RAR_SUFFIX)) {
      bdaType=BDAType.RAR;
      collectRarInfo(archive);
    }
 else     if (archive.exists(META_INF_BEANS_XML)) {
      BeansXml beansXML=parseBeansXML(archive,META_INF_BEANS_XML);
      BeanDiscoveryMode bdMode=beansXML.getBeanDiscoveryMode();
      if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
        if (logger.isLoggable(FINE)) {
          logger.log(FINE,CDILoggerInfo.PROCESSING_BDA_JAR,new Object[]{archive.getURI()});
        }
        bdaType=BDAType.JAR;
        collectJarInfo(archive,true,!bdMode.equals(BeanDiscoveryMode.ANNOTATED));
      }
 else {
        addBeansXMLURL(archive,META_INF_BEANS_XML);
      }
    }
 else     if (WeldUtils.isImplicitBeanArchive(context,archive)) {
      if (logger.isLoggable(FINE)) {
        logger.log(FINE,CDILoggerInfo.PROCESSING_BECAUSE_SCOPE_ANNOTATION,new Object[]{archive.getURI()});
      }
      bdaType=BDAType.JAR;
      collectJarInfo(archive,true,false);
    }
  }
 catch (  IOException e) {
    logger.log(SEVERE,e.getLocalizedMessage(),e);
  }
catch (  ClassNotFoundException cne) {
    logger.log(SEVERE,cne.getLocalizedMessage(),cne);
  }
}