Program: 29387
Project: 29387
Buggy source:
/** 
 * return resource in free list. If none is found, try to scale up the pool/purge pool and <br> return a new resource. returns null if the pool new resources cannot be created. <br>
 * @param alloc ResourceAllocator
 * @return ResourceHandle resource from pool
 * @throws PoolingException if unable to create a new resource
 */
protected ResourceHandle getResourceFromPool(ResourceAllocator alloc,ResourceSpec spec) throws PoolingException {
  ResourceHandle result=null;
  ResourceHandle h;
  ArrayList<ResourceHandle> freeResources=new ArrayList<ResourceHandle>();
  try {
    while ((h=ds.getResource()) != null) {
      if (h.hasConnectionErrorOccurred()) {
        ds.removeResource(h);
        continue;
      }
      if (matchConnection(h,alloc)) {
        boolean isValid=isConnectionValid(h,alloc);
        if (h.hasConnectionErrorOccurred() || !isValid) {
          if (failAllConnections) {
            h=createSingleResourceAndAdjustPool(alloc,spec);
            break;
          }
 else {
            ds.removeResource(h);
            continue;
          }
        }
        if (h.isShareable() == alloc.shareableWithinComponent()) {
          result=h;
          break;
        }
 else {
          freeResources.add(h);
        }
      }
 else {
        freeResources.add(h);
      }
    }
  }
  finally {
    for (    ResourceHandle freeResource : freeResources) {
      ds.returnResource(freeResource);
    }
    freeResources.clear();
  }
  if (result != null) {
    setResourceStateToBusy(result);
  }
 else {
    result=resizePoolAndGetNewResource(alloc);
  }
  return result;
}

Fixed version (ground truth):
/** 
 * return resource in free list. If none is found, try to scale up the pool/purge pool and <br> return a new resource. returns null if the pool new resources cannot be created. <br>
 * @param alloc ResourceAllocator
 * @return ResourceHandle resource from pool
 * @throws PoolingException if unable to create a new resource
 */
protected ResourceHandle getResourceFromPool(ResourceAllocator alloc,ResourceSpec spec) throws PoolingException {
  ResourceHandle result=null;
  ResourceHandle h;
  ArrayList<ResourceHandle> freeResources=new ArrayList<ResourceHandle>();
  try {
    while ((h=ds.getResource()) != null) {
      if (h.hasConnectionErrorOccurred()) {
        ds.removeResource(h);
        continue;
      }
      if (matchConnection(h,alloc)) {
        boolean isValid=isConnectionValid(h,alloc);
        if (h.hasConnectionErrorOccurred() || !isValid) {
          if (failAllConnections) {
            createSingleResourceAndAdjustPool(alloc,spec);
            break;
          }
 else {
            ds.removeResource(h);
            continue;
          }
        }
        if (h.isShareable() == alloc.shareableWithinComponent()) {
          result=h;
          break;
        }
 else {
          freeResources.add(h);
        }
      }
 else {
        freeResources.add(h);
      }
    }
  }
  finally {
    for (    ResourceHandle freeResource : freeResources) {
      ds.returnResource(freeResource);
    }
    freeResources.clear();
  }
  if (result != null) {
    setResourceStateToBusy(result);
  }
 else {
    result=resizePoolAndGetNewResource(alloc);
  }
  return result;
}