Program: 176050
Project: 176050
Buggy source:
/** 
 * Load entity metadata.
 * @param persistenceUnit the persistence unit
 */
private void loadEntityMetadata(String persistenceUnit){
  if (persistenceUnit == null) {
    throw new IllegalArgumentException("String_Node_Str" + persistenceUnit);
  }
  Map<String,PersistenceUnitMetadata> persistentUnitMetadataMap=kunderaMetadata.getApplicationMetadata().getPersistenceUnitMetadataMap();
  List<String> classesToScan;
  URL[] resources=null;
  String client=null;
  List<URL> managedURLs=null;
  if (persistentUnitMetadataMap == null || persistentUnitMetadataMap.isEmpty()) {
    log.error("String_Node_Str" + persistenceUnit + "String_Node_Str");
    throw new MetamodelLoaderException("String_Node_Str" + persistenceUnit + "String_Node_Str");
  }
 else {
    PersistenceUnitMetadata puMetadata=persistentUnitMetadataMap.get(persistenceUnit);
    classesToScan=puMetadata.getManagedClassNames();
    managedURLs=puMetadata.getManagedURLs();
    Map<String,Object> externalProperties=KunderaCoreUtils.getExternalProperties(persistenceUnit,externalPropertyMap,persistenceUnits);
    client=externalProperties != null ? (String)externalProperties.get(PersistenceProperties.KUNDERA_CLIENT_FACTORY) : null;
    if (client == null) {
      client=puMetadata.getClient();
    }
  }
  Reader reader;
  ApplicationMetadata appMetadata=kunderaMetadata.getApplicationMetadata();
  if (classesToScan == null || classesToScan.isEmpty()) {
    log.info("String_Node_Str" + persistenceUnit + "String_Node_Str");
    if (appMetadata.getMetamodelMap().get(persistenceUnit) != null) {
      log.info("String_Node_Str");
      return;
    }
    reader=new ClasspathReader();
  }
 else {
    reader=new ClasspathReader(classesToScan);
  }
  InputStream[] iStreams=null;
  PersistenceUnitMetadata puMetadata=persistentUnitMetadataMap.get(persistenceUnit);
  if (this.getClass().getClassLoader() instanceof URLClassLoader && !puMetadata.getExcludeUnlistedClasses()) {
    URL[] managedClasses=reader.findResources();
    if (managedClasses != null) {
      List<URL> managedResources=Arrays.asList(managedClasses);
      managedURLs.addAll(managedResources);
    }
  }
 else {
    iStreams=reader.findResourcesAsStream();
  }
  if (managedURLs != null) {
    resources=managedURLs.toArray(new URL[]{});
  }
  reader.addValidAnnotations(Entity.class.getName());
  Metamodel metamodel=appMetadata.getMetamodel(persistenceUnit);
  if (metamodel == null) {
    metamodel=new MetamodelImpl();
  }
  Map<String,EntityMetadata> entityMetadataMap=((MetamodelImpl)metamodel).getEntityMetadataMap();
  Map<String,Class<?>> entityNameToClassMap=((MetamodelImpl)metamodel).getEntityNameToClassMap();
  Map<String,List<String>> puToClazzMap=new HashMap<String,List<String>>();
  Map<String,IdDiscriptor> entityNameToKeyDiscriptorMap=new HashMap<String,IdDiscriptor>();
  List<Class<?>> classes=new ArrayList<Class<?>>();
  if (resources != null && resources.length > 0) {
    for (    URL resource : resources) {
      try {
        ResourceIterator itr=reader.getResourceIterator(resource,reader.getFilter());
        InputStream is=null;
        while ((is=itr.next()) != null) {
          classes.addAll(scanClassAndPutMetadata(is,reader,entityMetadataMap,entityNameToClassMap,persistenceUnit,client,puToClazzMap,entityNameToKeyDiscriptorMap));
        }
      }
 catch (      IOException e) {
        log.error("String_Node_Str",e);
        throw new MetamodelLoaderException("String_Node_Str");
      }
    }
  }
 else   if (iStreams != null) {
    try {
      for (      InputStream is : iStreams) {
        try {
          classes.addAll(scanClassAndPutMetadata(is,reader,entityMetadataMap,entityNameToClassMap,persistenceUnit,client,puToClazzMap,entityNameToKeyDiscriptorMap));
        }
  finally {
          if (is != null) {
            is.close();
          }
        }
      }
    }
 catch (    IOException e) {
      log.error("String_Node_Str",e);
      throw new MetamodelLoaderException("String_Node_Str",e);
    }
  }
  ((MetamodelImpl)metamodel).setEntityMetadataMap(entityMetadataMap);
  appMetadata.getMetamodelMap().put(persistenceUnit,metamodel);
  appMetadata.setClazzToPuMap(puToClazzMap);
  ((MetamodelImpl)metamodel).addKeyValues(entityNameToKeyDiscriptorMap);
  ((MetamodelImpl)metamodel).assignEmbeddables(kunderaMetadata.getApplicationMetadata().getMetaModelBuilder(persistenceUnit).getEmbeddables());
  ((MetamodelImpl)metamodel).assignManagedTypes(kunderaMetadata.getApplicationMetadata().getMetaModelBuilder(persistenceUnit).getManagedTypes());
  ((MetamodelImpl)metamodel).assignMappedSuperClass(kunderaMetadata.getApplicationMetadata().getMetaModelBuilder(persistenceUnit).getMappedSuperClassTypes());
}

Fixed version (ground truth):
/** 
 * Load entity metadata.
 * @param persistenceUnit the persistence unit
 */
private void loadEntityMetadata(String persistenceUnit){
  if (persistenceUnit == null) {
    throw new IllegalArgumentException("String_Node_Str" + persistenceUnit);
  }
  Map<String,PersistenceUnitMetadata> persistentUnitMetadataMap=kunderaMetadata.getApplicationMetadata().getPersistenceUnitMetadataMap();
  List<String> classesToScan;
  URL[] resources=null;
  String client=null;
  List<URL> managedURLs=null;
  if (persistentUnitMetadataMap == null || persistentUnitMetadataMap.isEmpty()) {
    log.error("String_Node_Str" + persistenceUnit + "String_Node_Str");
    throw new MetamodelLoaderException("String_Node_Str" + persistenceUnit + "String_Node_Str");
  }
 else {
    PersistenceUnitMetadata puMetadata=persistentUnitMetadataMap.get(persistenceUnit);
    classesToScan=puMetadata.getManagedClassNames();
    managedURLs=puMetadata.getManagedURLs();
    client=getClientFactoryName(persistenceUnit);
  }
  Reader reader;
  ApplicationMetadata appMetadata=kunderaMetadata.getApplicationMetadata();
  if (classesToScan == null || classesToScan.isEmpty()) {
    log.info("String_Node_Str" + persistenceUnit + "String_Node_Str");
    if (appMetadata.getMetamodelMap().get(persistenceUnit) != null) {
      log.info("String_Node_Str");
      return;
    }
    reader=new ClasspathReader();
  }
 else {
    reader=new ClasspathReader(classesToScan);
  }
  InputStream[] iStreams=null;
  PersistenceUnitMetadata puMetadata=persistentUnitMetadataMap.get(persistenceUnit);
  if (this.getClass().getClassLoader() instanceof URLClassLoader && !puMetadata.getExcludeUnlistedClasses()) {
    URL[] managedClasses=reader.findResources();
    if (managedClasses != null) {
      List<URL> managedResources=Arrays.asList(managedClasses);
      managedURLs.addAll(managedResources);
    }
  }
 else {
    iStreams=reader.findResourcesAsStream();
  }
  if (managedURLs != null) {
    resources=managedURLs.toArray(new URL[]{});
  }
  reader.addValidAnnotations(Entity.class.getName());
  Metamodel metamodel=appMetadata.getMetamodel(persistenceUnit);
  if (metamodel == null) {
    metamodel=new MetamodelImpl();
  }
  Map<String,EntityMetadata> entityMetadataMap=((MetamodelImpl)metamodel).getEntityMetadataMap();
  Map<String,Class<?>> entityNameToClassMap=((MetamodelImpl)metamodel).getEntityNameToClassMap();
  Map<String,List<String>> puToClazzMap=new HashMap<String,List<String>>();
  Map<String,IdDiscriptor> entityNameToKeyDiscriptorMap=new HashMap<String,IdDiscriptor>();
  List<Class<?>> classes=new ArrayList<Class<?>>();
  if (resources != null && resources.length > 0) {
    for (    URL resource : resources) {
      try {
        ResourceIterator itr=reader.getResourceIterator(resource,reader.getFilter());
        InputStream is=null;
        while ((is=itr.next()) != null) {
          classes.addAll(scanClassAndPutMetadata(is,reader,entityMetadataMap,entityNameToClassMap,persistenceUnit,client,puToClazzMap,entityNameToKeyDiscriptorMap));
        }
      }
 catch (      IOException e) {
        log.error("String_Node_Str",e);
        throw new MetamodelLoaderException("String_Node_Str");
      }
    }
  }
 else   if (iStreams != null) {
    try {
      for (      InputStream is : iStreams) {
        try {
          classes.addAll(scanClassAndPutMetadata(is,reader,entityMetadataMap,entityNameToClassMap,persistenceUnit,client,puToClazzMap,entityNameToKeyDiscriptorMap));
        }
  finally {
          if (is != null) {
            is.close();
          }
        }
      }
    }
 catch (    IOException e) {
      log.error("String_Node_Str",e);
      throw new MetamodelLoaderException("String_Node_Str",e);
    }
  }
  ((MetamodelImpl)metamodel).setEntityMetadataMap(entityMetadataMap);
  appMetadata.getMetamodelMap().put(persistenceUnit,metamodel);
  appMetadata.setClazzToPuMap(puToClazzMap);
  ((MetamodelImpl)metamodel).addKeyValues(entityNameToKeyDiscriptorMap);
  ((MetamodelImpl)metamodel).assignEmbeddables(kunderaMetadata.getApplicationMetadata().getMetaModelBuilder(persistenceUnit).getEmbeddables());
  ((MetamodelImpl)metamodel).assignManagedTypes(kunderaMetadata.getApplicationMetadata().getMetaModelBuilder(persistenceUnit).getManagedTypes());
  ((MetamodelImpl)metamodel).assignMappedSuperClass(kunderaMetadata.getApplicationMetadata().getMetaModelBuilder(persistenceUnit).getMappedSuperClassTypes());
}