Program: 29811
Project: 29811
Buggy source:
private void addJNDIBindings(JndiNameEnvironment env,ScopeType scope,Collection<JNDIBinding> jndiBindings){
  addEnvironmentProperties(scope,env.getEnvironmentProperties().iterator(),jndiBindings);
  for (Iterator itr=env.getJmsDestinationReferenceDescriptors().iterator(); itr.hasNext(); ) {
    JmsDestinationReferenceDescriptor next=(JmsDestinationReferenceDescriptor)itr.next();
    if (!dependencyAppliesToScope(next,scope)) {
      continue;
    }
    next.checkType();
    jndiBindings.add(getCompEnvBinding(next));
  }
  addDataSourceBindings(env,scope,jndiBindings);
  for (Iterator itr=env.getEjbReferenceDescriptors().iterator(); itr.hasNext(); ) {
    EjbReferenceDescriptor next=(EjbReferenceDescriptor)itr.next();
    if (!dependencyAppliesToScope(next,scope)) {
      continue;
    }
    String name=descriptorToLogicalJndiName(next);
    EjbReferenceProxy proxy=new EjbReferenceProxy(next);
    jndiBindings.add(new CompEnvBinding(name,proxy));
  }
  for (Iterator itr=env.getMessageDestinationReferenceDescriptors().iterator(); itr.hasNext(); ) {
    MessageDestinationReferenceDescriptor next=(MessageDestinationReferenceDescriptor)itr.next();
    if (!dependencyAppliesToScope(next,scope)) {
      continue;
    }
    jndiBindings.add(getCompEnvBinding(next));
  }
  addResourceReferences(scope,env.getResourceReferenceDescriptors().iterator(),jndiBindings);
  for (  EntityManagerFactoryReferenceDescriptor next : env.getEntityManagerFactoryReferenceDescriptors()) {
    if (!dependencyAppliesToScope(next,scope)) {
      continue;
    }
    String name=descriptorToLogicalJndiName(next);
    Object value=new FactoryForEntityManagerFactoryWrapper(next.getUnitName(),invMgr,this);
    jndiBindings.add(new CompEnvBinding(name,value));
  }
  for (Iterator itr=env.getServiceReferenceDescriptors().iterator(); itr.hasNext(); ) {
    ServiceReferenceDescriptor next=(ServiceReferenceDescriptor)itr.next();
    if (!dependencyAppliesToScope(next,scope)) {
      continue;
    }
    if (next.getMappedName() != null) {
      next.setName(next.getMappedName());
    }
    String name=descriptorToLogicalJndiName(next);
    WebServiceRefProxy value=new WebServiceRefProxy(next);
    jndiBindings.add(new CompEnvBinding(name,value));
  }
  for (  EntityManagerReferenceDescriptor next : env.getEntityManagerReferenceDescriptors()) {
    if (!dependencyAppliesToScope(next,scope)) {
      continue;
    }
    String name=descriptorToLogicalJndiName(next);
    FactoryForEntityManagerWrapper value=new FactoryForEntityManagerWrapper(next,this);
    jndiBindings.add(new CompEnvBinding(name,value));
  }
  return;
}

Fixed version (ground truth):
private void addJNDIBindings(JndiNameEnvironment env,ScopeType scope,Collection<JNDIBinding> jndiBindings){
  addEnvironmentProperties(scope,env.getEnvironmentProperties().iterator(),jndiBindings);
  for (Iterator itr=env.getResourceEnvReferenceDescriptors().iterator(); itr.hasNext(); ) {
    ResourceEnvReferenceDescriptor next=(ResourceEnvReferenceDescriptor)itr.next();
    if (!dependencyAppliesToScope(next,scope)) {
      continue;
    }
    next.checkType();
    jndiBindings.add(getCompEnvBinding(next));
  }
  addDataSourceBindings(env,scope,jndiBindings);
  for (Iterator itr=env.getEjbReferenceDescriptors().iterator(); itr.hasNext(); ) {
    EjbReferenceDescriptor next=(EjbReferenceDescriptor)itr.next();
    if (!dependencyAppliesToScope(next,scope)) {
      continue;
    }
    String name=descriptorToLogicalJndiName(next);
    EjbReferenceProxy proxy=new EjbReferenceProxy(next);
    jndiBindings.add(new CompEnvBinding(name,proxy));
  }
  for (Iterator itr=env.getMessageDestinationReferenceDescriptors().iterator(); itr.hasNext(); ) {
    MessageDestinationReferenceDescriptor next=(MessageDestinationReferenceDescriptor)itr.next();
    if (!dependencyAppliesToScope(next,scope)) {
      continue;
    }
    jndiBindings.add(getCompEnvBinding(next));
  }
  addResourceReferences(scope,env.getResourceReferenceDescriptors().iterator(),jndiBindings);
  for (  EntityManagerFactoryReferenceDescriptor next : env.getEntityManagerFactoryReferenceDescriptors()) {
    if (!dependencyAppliesToScope(next,scope)) {
      continue;
    }
    String name=descriptorToLogicalJndiName(next);
    Object value=new FactoryForEntityManagerFactoryWrapper(next.getUnitName(),invMgr,this);
    jndiBindings.add(new CompEnvBinding(name,value));
  }
  for (Iterator itr=env.getServiceReferenceDescriptors().iterator(); itr.hasNext(); ) {
    ServiceReferenceDescriptor next=(ServiceReferenceDescriptor)itr.next();
    if (!dependencyAppliesToScope(next,scope)) {
      continue;
    }
    if (next.getMappedName() != null) {
      next.setName(next.getMappedName());
    }
    String name=descriptorToLogicalJndiName(next);
    WebServiceRefProxy value=new WebServiceRefProxy(next);
    jndiBindings.add(new CompEnvBinding(name,value));
  }
  for (  EntityManagerReferenceDescriptor next : env.getEntityManagerReferenceDescriptors()) {
    if (!dependencyAppliesToScope(next,scope)) {
      continue;
    }
    String name=descriptorToLogicalJndiName(next);
    FactoryForEntityManagerWrapper value=new FactoryForEntityManagerWrapper(next,this);
    jndiBindings.add(new CompEnvBinding(name,value));
  }
  return;
}