nus-yam/ex-repair huggingface dataset:
Program: 3468
Project: 3468
Buggy source:
/** 
 * General matrix multiply
 * @param A
 * @param B
 * @param C
 * @param alpha
 * @param beta
 * @return
 */
public static INDArray gemm(INDArray A,INDArray B,INDArray C,float alpha,float beta){
  DataTypeValidation.assertFloat(A,B,C);
  Pointer cAPointer=getPointer(A);
  Pointer cBPointer=getPointer(B);
  Pointer cCPointer=getPointer(C);
  try {
    JCublas.cublasSgemm('n','n',C.rows(),C.columns(),A.columns(),alpha,cAPointer,A.rows(),cBPointer,B.rows(),beta,cCPointer,C.rows());
  }
 catch (  Exception e) {
    throw new RuntimeException("String_Node_Str" + JCuda.cudaGetErrorString(JCuda.cudaGetLastError()),e);
  }
  return C;
}

Fixed version (ground truth):
/** 
 * General matrix multiply
 * @param A
 * @param B
 * @param C
 * @param alpha
 * @param beta
 * @return
 */
public static INDArray gemm(INDArray A,INDArray B,INDArray C,float alpha,float beta){
  DataTypeValidation.assertFloat(A,B,C);
  Pointer cAPointer=getPointer(A);
  Pointer cBPointer=getPointer(B);
  Pointer cCPointer=getPointer(C);
  JCublas.cublasSgemm('n','n',C.rows(),C.columns(),A.columns(),alpha,cAPointer,A.rows(),cBPointer,B.rows(),beta,cCPointer,C.rows());
  return C;
}
Program: 3469
Project: 3469
Buggy source:
@Override public IComplexNumber getComplex(int i){
  return dataType() == DataBuffer.FLOAT ? getComplexFloat(i) : getComplexDouble(i);
}

Fixed version (ground truth):
@Override public IComplexNumber getComplex(int i){
  ensureNotFreed();
  return dataType() == DataBuffer.FLOAT ? getComplexFloat(i) : getComplexDouble(i);
}
Program: 3470
Project: 3470
Buggy source:
/** 
 * Copy the data of this buffer to another buffer on the gpu
 * @param to the buffer to copy data to
 */
protected void copyTo(JCudaBuffer to){
  if (to.dataType() != dataType())   throw new IllegalArgumentException("String_Node_Str");
  JCuda.cudaMemcpy(to.pointer(),pointer(),length() * elementSize(),cudaMemcpyKind.cudaMemcpyDeviceToDevice);
}

Fixed version (ground truth):
/** 
 * Copy the data of this buffer to another buffer on the gpu
 * @param to the buffer to copy data to
 */
protected void copyTo(JCudaBuffer to){
  ensureNotFreed();
  if (to.dataType() != dataType())   throw new IllegalArgumentException("String_Node_Str");
  JCuda.cudaMemcpy(to.pointer(),pointer(),length() * elementSize(),cudaMemcpyKind.cudaMemcpyDeviceToDevice);
}
Program: 3471
Project: 3471
Buggy source:
/** 
 * Set an individual element
 * @param index the index of the element
 * @param from  the element to get data from
 */
protected void set(int index,Pointer from){
  set(index,1,from);
}

Fixed version (ground truth):
/** 
 * Set an individual element
 * @param index the index of the element
 * @param from  the element to get data from
 */
protected void set(int index,Pointer from){
  ensureNotFreed();
  set(index,1,from);
}
Program: 3472
Project: 3472
Buggy source:
@Override public void destroy(){
  try {
    if (!freed) {
      JCuda.cudaFree(pointer);
      freed=true;
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
@Override public synchronized void destroy(){
  ensureNotFreed();
  try {
    if (!freed.get()) {
      JCuda.cudaFree(pointer);
      freed.set(true);
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
Program: 3473
Project: 3473
Buggy source:
@Override public int getInt(int ix){
  return 0;
}

Fixed version (ground truth):
@Override public int getInt(int ix){
  ensureNotFreed();
  return 0;
}
Program: 3474
Project: 3474
Buggy source:
@Override public DataBuffer dup(){
  throw new UnsupportedOperationException();
}

Fixed version (ground truth):
@Override public DataBuffer dup(){
  ensureNotFreed();
  throw new UnsupportedOperationException();
}
Program: 3475
Project: 3475
Buggy source:
@Override public void assign(int[] offsets,int[] strides,DataBuffer... buffers){
  assign(offsets,strides,length(),buffers);
}

Fixed version (ground truth):
@Override public void assign(int[] offsets,int[] strides,DataBuffer... buffers){
  ensureNotFreed();
  assign(offsets,strides,length(),buffers);
}
Program: 3476
Project: 3476
Buggy source:
@Override public void setData(double[] data){
  if (data.length != length)   throw new IllegalArgumentException("String_Node_Str" + length() + "String_Node_Str"+ data.length);
  if (pointer() == null)   alloc();
  JCuda.cudaMemcpy(pointer(),Pointer.to(data),data.length * elementSize(),cudaMemcpyKind.cudaMemcpyHostToDevice);
}

Fixed version (ground truth):
@Override public void setData(double[] data){
  ensureNotFreed();
  if (data.length != length)   throw new IllegalArgumentException("String_Node_Str" + length() + "String_Node_Str"+ data.length);
  if (pointer() == null)   alloc();
  JCuda.cudaMemcpy(pointer(),Pointer.to(data),data.length * elementSize(),cudaMemcpyKind.cudaMemcpyHostToDevice);
}
Program: 3477
Project: 3477
Buggy source:
@Override public double getDouble(int i){
  double[] d=new double[1];
  Pointer p=Pointer.to(d);
  get(i,p);
  return d[0];
}

Fixed version (ground truth):
@Override public double getDouble(int i){
  ensureNotFreed();
  double[] d=new double[1];
  Pointer p=Pointer.to(d);
  get(i,p);
  return d[0];
}
Program: 3478
Project: 3478
Buggy source:
@Override public float[] getFloatsAt(int offset,int inc,int length){
  return ArrayUtil.toFloats(getDoublesAt(offset,1,length));
}

Fixed version (ground truth):
@Override public float[] getFloatsAt(int offset,int inc,int length){
  ensureNotFreed();
  return ArrayUtil.toFloats(getDoublesAt(offset,1,length));
}
Program: 3479
Project: 3479
Buggy source:
@Override public double[] asDouble(){
  double[] ret=new double[length];
  Pointer p=Pointer.to(ret);
  JCublas.cublasGetVector(length,elementSize(),pointer(),1,p,1);
  return ret;
}

Fixed version (ground truth):
@Override public double[] asDouble(){
  ensureNotFreed();
  double[] ret=new double[length];
  Pointer p=Pointer.to(ret);
  JCublas.cublasGetVector(length,elementSize(),pointer(),1,p,1);
  return ret;
}
Program: 3480
Project: 3480
Buggy source:
@Override public DataBuffer dup(){
  CudaDoubleDataBuffer buffer=new CudaDoubleDataBuffer(length());
  copyTo(buffer);
  return buffer;
}

Fixed version (ground truth):
@Override public DataBuffer dup(){
  ensureNotFreed();
  CudaDoubleDataBuffer buffer=new CudaDoubleDataBuffer(length());
  copyTo(buffer);
  return buffer;
}
Program: 3481
Project: 3481
Buggy source:
@Override public void assign(Number value,int offset){
  int arrLength=length - offset;
  double[] data=new double[arrLength];
  for (int i=0; i < data.length; i++)   data[i]=value.doubleValue();
  set(offset,arrLength,Pointer.to(data));
}

Fixed version (ground truth):
@Override public void assign(Number value,int offset){
  ensureNotFreed();
  int arrLength=length - offset;
  double[] data=new double[arrLength];
  for (int i=0; i < data.length; i++)   data[i]=value.doubleValue();
  set(offset,arrLength,Pointer.to(data));
}
Program: 3482
Project: 3482
Buggy source:
@Override public double[] getDoublesAt(int offset,int inc,int length){
  if (offset + length > length())   length-=offset;
  double[] ret=new double[length];
  Pointer p=Pointer.to(ret);
  get(offset,inc,length,p);
  return ret;
}

Fixed version (ground truth):
@Override public double[] getDoublesAt(int offset,int inc,int length){
  ensureNotFreed();
  if (offset + length > length())   length-=offset;
  double[] ret=new double[length];
  Pointer p=Pointer.to(ret);
  get(offset,inc,length,p);
  return ret;
}
Program: 3483
Project: 3483
Buggy source:
@Override public void init(INDArray x,INDArray y,INDArray z,int n){
  super.init(x,y,z,n);
  if (x instanceof IComplexNDArray) {
    this.maxComplex=Nd4j.getExecutioner().execAndReturn(new Max(x)).currentResultComplex();
    IComplexNDArray complexX=(IComplexNDArray)x;
    this.y=Transforms.exp(complexX.sub(maxComplex));
    this.sumComplex=Nd4j.getExecutioner().execAndReturn(new Sum(y)).currentResultComplex();
    this.y.divi(sumComplex);
    this.extraArgs=new Object[]{maxComplex,sumComplex};
  }
 else {
    this.max=Nd4j.getExecutioner().execAndReturn(new Max(x)).currentResult();
    INDArray xMinusMax=x.sub(max);
    this.y=Transforms.exp(xMinusMax);
    this.sum=Nd4j.getExecutioner().execAndReturn(new Sum(this.y)).currentResult();
    this.y.divi(sum);
    this.extraArgs=new Object[]{max,sum};
  }
}

Fixed version (ground truth):
@Override public void init(INDArray x,INDArray y,INDArray z,int n){
  super.init(x,y,z,n);
  if (x instanceof IComplexNDArray) {
    this.maxComplex=Nd4j.getExecutioner().execAndReturn(new Max(x)).currentResultComplex();
    IComplexNDArray complexX=(IComplexNDArray)x;
    this.y=Transforms.exp(complexX.sub(maxComplex));
    if (this.y.shape().length < 2) {
      this.sumComplex=Nd4j.getExecutioner().execAndReturn(new Sum(y)).currentResultComplex();
      this.y.divi(sumComplex);
    }
 else {
      throw new NotImplementedException("String_Node_Str");
    }
    this.extraArgs=new Object[]{maxComplex,sumComplex};
  }
 else {
    this.max=Nd4j.getExecutioner().execAndReturn(new Max(x)).currentResult();
    INDArray xMinusMax=x.sub(max);
    this.y=Transforms.exp(xMinusMax);
    if (this.y.shape().length < 2) {
      this.sum=Nd4j.getExecutioner().execAndReturn(new Sum(this.y)).currentResult();
      this.y.divi(sum);
      this.extraArgs=new Object[]{max,sum};
    }
 else {
      INDArray aSum=this.y.sum(1).repmat(new int[]{this.y.shape()[1],1}).transpose();
      this.y.divi(aSum);
      this.extraArgs=new Object[]{max,aSum};
    }
  }
}
Program: 3484
Project: 3484
Buggy source:
/** 
 * Binarizes the dataset such that any number greater than cutoff is 1 otherwise zero
 * @param cutoff the cutoff point
 */
@Override public void binarize(double cutoff){
  for (int i=0; i < getFeatures().length(); i++) {
    double curr=(double)getFeatures().getScalar(i).element();
    if (curr > cutoff)     getFeatures().put(i,Nd4j.scalar(1));
 else     getFeatures().put(i,Nd4j.scalar(0));
  }
}

Fixed version (ground truth):
/** 
 * Binarizes the dataset such that any number greater than cutoff is 1 otherwise zero
 * @param cutoff the cutoff point
 */
@Override public void binarize(double cutoff){
  INDArray linear=getFeatureMatrix().linearView();
  for (int i=0; i < getFeatures().length(); i++) {
    double curr=linear.getDouble(i);
    if (curr > cutoff)     getFeatures().putScalar(i,1);
 else     getFeatures().putScalar(i,0);
  }
}
Program: 3485
Project: 3485
Buggy source:
@Override public IComplexNDArray scal(IComplexDouble alpha,IComplexNDArray x){
  return SimpleJCublas.scal(alpha,x.linearView());
}

Fixed version (ground truth):
@Override public IComplexNDArray scal(IComplexDouble alpha,IComplexNDArray x){
  return SimpleJCublas.scal(alpha,x);
}
Program: 3486
Project: 3486
Buggy source:
@Override public IComplexNDArray copy(IComplexNDArray x,IComplexNDArray y){
  SimpleJCublas.copy(x.linearView(),y.linearView());
  return y;
}

Fixed version (ground truth):
@Override public IComplexNDArray copy(IComplexNDArray x,IComplexNDArray y){
  SimpleJCublas.copy(x,y);
  return y;
}
Program: 3487
Project: 3487
Buggy source:
@Override public INDArray swap(INDArray x,INDArray y){
  SimpleJCublas.swap(x.linearView(),y.linearView());
  return y;
}

Fixed version (ground truth):
@Override public INDArray swap(INDArray x,INDArray y){
  SimpleJCublas.swap(x,y);
  return y;
}
Program: 3488
Project: 3488
Buggy source:
@Override public IComplexNDArray axpy(IComplexNumber da,IComplexNDArray dx,IComplexNDArray dy){
  if (da instanceof IComplexDouble) {
    SimpleJCublas.axpy((IComplexDouble)da,dx.linearView(),dy.linearView());
  }
 else   SimpleJCublas.axpy((IComplexFloat)da,dx.linearView(),dy.linearView());
  return dy;
}

Fixed version (ground truth):
@Override public IComplexNDArray axpy(IComplexNumber da,IComplexNDArray dx,IComplexNDArray dy){
  if (da instanceof IComplexDouble) {
    SimpleJCublas.axpy((IComplexDouble)da,dx,dy);
  }
 else   SimpleJCublas.axpy((IComplexFloat)da,dx,dy);
  return dy;
}
Program: 3489
Project: 3489
Buggy source:
protected void doSampleUniform(Pointer out,float min,float max,int n){
  JCurand.curandGenerateUniform(random.generator(),out,n);
  String functionName="String_Node_Str";
  CUfunction func=KernelFunctionLoader.getInstance().getFunction(functionName,"String_Node_Str");
  if (func == null)   throw new IllegalArgumentException("String_Node_Str" + functionName + "String_Node_Str");
  int blocks=PointerUtil.getNumBlocks(n,128,64);
  int threads=PointerUtil.getNumThreads(n,64);
  Pointer kernelParams=Pointer.to(Pointer.to(new int[]{n}),Pointer.to(new double[]{min}),Pointer.to(new double[]{max}),Pointer.to(out),Pointer.to(random.generator()));
  KernelFunctions.invoke(blocks,threads,func,kernelParams);
}

Fixed version (ground truth):
protected void doSampleUniform(Pointer out,float min,float max,int n){
  JCurand.curandGenerateUniform(random.generator(),out,n);
  String functionName="String_Node_Str";
  CUfunction func=KernelFunctionLoader.getInstance().getFunction(functionName,"String_Node_Str");
  if (func == null)   throw new IllegalArgumentException("String_Node_Str" + functionName + "String_Node_Str");
  int blocks=PointerUtil.getNumBlocks(n,128,64);
  int threads=PointerUtil.getNumThreads(n,64);
  Pointer kernelParams=Pointer.to(Pointer.to(new int[]{n}),Pointer.to(new float[]{min}),Pointer.to(new float[]{max}),Pointer.to(out),Pointer.to(random.generator()));
  KernelFunctions.invoke(blocks,threads,func,kernelParams);
}
Program: 3490
Project: 3490
Buggy source:
/** 
 * Scale by 1 / norm2 of the matrix
 * @param toScale the ndarray to scale
 * @return the scaled ndarray
 */
public static INDArray unitVec(INDArray toScale){
  double length=toScale.norm2(Integer.MAX_VALUE).getDouble(0);
  if (length > 0) {
    if (toScale.data().dataType().equals(DataBuffer.FLOAT))     return Nd4j.getBlasWrapper().scal(1.0f / length,toScale);
 else     return Nd4j.getBlasWrapper().scal(1.0 / length,toScale);
  }
  return toScale;
}

Fixed version (ground truth):
/** 
 * Scale by 1 / norm2 of the matrix
 * @param toScale the ndarray to scale
 * @return the scaled ndarray
 */
public static INDArray unitVec(INDArray toScale){
  double length=toScale.norm2(Integer.MAX_VALUE).getDouble(0);
  if (length > 0) {
    if (toScale.data().dataType().equals(DataBuffer.FLOAT))     return Nd4j.getBlasWrapper().scal(1.0f / (float)length,toScale);
 else     return Nd4j.getBlasWrapper().scal(1.0 / length,toScale);
  }
  return toScale;
}
Program: 3491
Project: 3491
Buggy source:
/** 
 * Returns the squared (Euclidean) distance.
 */
@Override public double squaredDistance(INDArray other){
  double sd=0.0;
  if (other instanceof IComplexNDArray) {
    IComplexNDArray n=(IComplexNDArray)other;
    IComplexNDArray nLinear=n.linearView();
    for (int i=0; i < length; i++) {
      IComplexNumber diff=linearView().getComplex(i).sub(nLinear.getComplex(i));
      double d=(double)diff.absoluteValue();
      sd+=d * d;
    }
    return sd;
  }
  for (int i=0; i < length; i++) {
    INDArray linear=other.linearView();
    IComplexNumber diff=linearView().getComplex(i).sub(linear.getDouble(i));
    double d=(double)diff.absoluteValue();
    sd+=d * d;
  }
  return sd;
}

Fixed version (ground truth):
/** 
 * Returns the squared (Euclidean) distance.
 */
@Override public double squaredDistance(INDArray other){
  double sd=0.0;
  if (other instanceof IComplexNDArray) {
    IComplexNDArray n=(IComplexNDArray)other;
    IComplexNDArray nLinear=n.linearView();
    for (int i=0; i < length; i++) {
      IComplexNumber diff=linearView().getComplex(i).sub(nLinear.getComplex(i));
      double d=diff.absoluteValue().doubleValue();
      sd+=d * d;
    }
    return sd;
  }
  for (int i=0; i < length; i++) {
    INDArray linear=other.linearView();
    IComplexNumber diff=linearView().getComplex(i).sub(linear.getDouble(i));
    double d=diff.absoluteValue().doubleValue();
    sd+=d * d;
  }
  return sd;
}
Program: 3492
Project: 3492
Buggy source:
/** 
 * The transformation for a given value (a scalar ndarray)
 * @param value the value to applyTransformToOrigin (a scalar ndarray)
 * @param i     the index of the element being acted upon
 * @return the transformed value based on the input
 */
@Override public Object apply(INDArray from,Object value,int i){
  Object curr=getFromOrigin(from,i);
  double originValue=(double)(curr instanceof IComplexNumber ? ((IComplexNumber)curr).absoluteValue() : (double)curr);
  double otherValue=(double)(value instanceof IComplexNumber ? ((IComplexNumber)value).absoluteValue() : (double)value);
  if (originValue == otherValue) {
    if (value instanceof IComplexNumber) {
      return Nd4j.createDouble(1,0);
    }
 else     return (double)1;
  }
 else {
    if (value instanceof IComplexNumber)     return Nd4j.createDouble(0,0);
 else     return (double)0;
  }
}

Fixed version (ground truth):
/** 
 * The transformation for a given value (a scalar ndarray)
 * @param value the value to applyTransformToOrigin (a scalar ndarray)
 * @param i     the index of the element being acted upon
 * @return the transformed value based on the input
 */
@Override public Object apply(INDArray from,Object value,int i){
  Object curr=getFromOrigin(from,i);
  double originValue=(curr instanceof IComplexNumber ? ((IComplexNumber)curr).absoluteValue().doubleValue() : (double)curr);
  double otherValue=(double)(value instanceof IComplexNumber ? ((IComplexNumber)value).absoluteValue().doubleValue() : (double)value);
  if (originValue == otherValue) {
    if (value instanceof IComplexNumber) {
      return Nd4j.createDouble(1,0);
    }
 else     return (double)1;
  }
 else {
    if (value instanceof IComplexNumber)     return Nd4j.createDouble(0,0);
 else     return (double)0;
  }
}
Program: 3493
Project: 3493
Buggy source:
/** 
 * The transformation for a given value (a scalar ndarray)
 * @param value the value to applyTransformToOrigin (a scalar ndarray)
 * @param i     the index of the element being acted upon
 * @return the transformed value based on the input
 */
@Override public Object apply(INDArray from,Object value,int i){
  Object curr=getFromOrigin(from,i);
  double originValue=(double)(curr instanceof IComplexNDArray ? ((IComplexNumber)curr).absoluteValue() : (double)curr);
  double otherValue=(double)(value instanceof IComplexNDArray ? ((IComplexNumber)value).absoluteValue() : (double)value);
  if (originValue > otherValue) {
    if (value instanceof IComplexNumber) {
      return Nd4j.createDouble(1,0);
    }
 else     return (double)1;
  }
 else {
    if (value instanceof IComplexNumber)     return Nd4j.createDouble(0,0);
 else     return (double)0;
  }
}

Fixed version (ground truth):
/** 
 * The transformation for a given value (a scalar ndarray)
 * @param value the value to applyTransformToOrigin (a scalar ndarray)
 * @param i     the index of the element being acted upon
 * @return the transformed value based on the input
 */
@Override public Object apply(INDArray from,Object value,int i){
  Object curr=getFromOrigin(from,i);
  double originValue=(curr instanceof IComplexNDArray ? ((IComplexNumber)curr).absoluteValue().doubleValue() : (double)curr);
  double otherValue=(value instanceof IComplexNDArray ? ((IComplexNumber)value).absoluteValue().doubleValue() : (double)value);
  if (originValue > otherValue) {
    if (value instanceof IComplexNumber) {
      return Nd4j.createDouble(1,0);
    }
 else     return (double)1;
  }
 else {
    if (value instanceof IComplexNumber)     return Nd4j.createDouble(0,0);
 else     return (double)0;
  }
}
Program: 3494
Project: 3494
Buggy source:
/** 
 * The transformation for a given value (a scalar ndarray)
 * @param value the value to applyTransformToOrigin (a scalar ndarray)
 * @param i     the index of the element being acted upon
 * @return the transformed value based on the input
 */
@Override public Object apply(INDArray from,Object value,int i){
  Object curr=getFromOrigin(from,i);
  double originValue=(double)(curr instanceof IComplexNDArray ? ((IComplexNumber)curr).absoluteValue() : (double)curr);
  double otherValue=(double)(value instanceof IComplexNDArray ? ((IComplexNumber)value).absoluteValue() : (double)value);
  if (originValue < otherValue) {
    if (value instanceof IComplexNumber)     return Nd4j.createDouble(1,0);
 else     return 1;
  }
 else {
    if (value instanceof IComplexNDArray)     return Nd4j.createDouble(0,0);
 else     return 0;
  }
}

Fixed version (ground truth):
/** 
 * The transformation for a given value (a scalar ndarray)
 * @param value the value to applyTransformToOrigin (a scalar ndarray)
 * @param i     the index of the element being acted upon
 * @return the transformed value based on the input
 */
@Override public Object apply(INDArray from,Object value,int i){
  Object curr=getFromOrigin(from,i);
  double originValue=(curr instanceof IComplexNDArray ? ((IComplexNumber)curr).absoluteValue().doubleValue() : (double)curr);
  double otherValue=(value instanceof IComplexNDArray ? ((IComplexNumber)value).absoluteValue().doubleValue() : (double)value);
  if (originValue < otherValue) {
    if (value instanceof IComplexNumber)     return Nd4j.createDouble(1,0);
 else     return 1;
  }
 else {
    if (value instanceof IComplexNDArray)     return Nd4j.createDouble(0,0);
 else     return 0;
  }
}
Program: 3495
Project: 3495
Buggy source:
/** 
 * The transformation for a given value (a scalar ndarray)
 * @param value the value to applyTransformToOrigin (a scalar ndarray)
 * @param i     the index of the element being acted upon
 * @return the transformed value based on the input
 */
@Override public Object apply(INDArray from,Object value,int i){
  Object curr=getFromOrigin(from,i);
  double originValue=(double)(curr instanceof IComplexNumber ? ((IComplexNumber)curr).absoluteValue() : (double)curr);
  double otherValue=(double)(value instanceof IComplexNumber ? ((IComplexNumber)value).absoluteValue() : (double)value);
  if (originValue != otherValue) {
    if (value instanceof IComplexNumber) {
      return Nd4j.createDouble(1,0);
    }
 else     return (double)1;
  }
 else {
    if (value instanceof IComplexNumber)     return Nd4j.createDouble(0,0);
 else     return (double)0;
  }
}

Fixed version (ground truth):
/** 
 * The transformation for a given value (a scalar ndarray)
 * @param value the value to applyTransformToOrigin (a scalar ndarray)
 * @param i     the index of the element being acted upon
 * @return the transformed value based on the input
 */
@Override public Object apply(INDArray from,Object value,int i){
  Object curr=getFromOrigin(from,i);
  double originValue=(curr instanceof IComplexNumber ? ((IComplexNumber)curr).absoluteValue().doubleValue() : (double)curr);
  double otherValue=(value instanceof IComplexNumber ? ((IComplexNumber)value).absoluteValue().doubleValue() : (double)value);
  if (originValue != otherValue) {
    if (value instanceof IComplexNumber) {
      return Nd4j.createDouble(1,0);
    }
 else     return (double)1;
  }
 else {
    if (value instanceof IComplexNumber)     return Nd4j.createDouble(0,0);
 else     return (double)0;
  }
}
Program: 3496
Project: 3496
Buggy source:
@Test public void testGetMulti(){
  assertEquals(8,n.length());
  assertEquals(true,Arrays.equals(ArrayUtil.of(2,2,2),n.shape()));
  float val=(float)n.getScalar(1,1,1).element();
  assertEquals(8.0,val,1e-6);
}

Fixed version (ground truth):
@Test public void testGetMulti(){
  assertEquals(8,n.length());
  assertEquals(true,Arrays.equals(ArrayUtil.of(2,2,2),n.shape()));
  float val=(float)n.getScalar(new int[]{1,1,1}).element();
  assertEquals(8.0,val,1e-6);
}
Program: 3497
Project: 3497
Buggy source:
/** 
 * Release the lock if it's currently held by the calling thread. If the current thread does not hold the lock, and error will be thrown.
 */
public synchronized void release(){
  checkThread();
  thread=null;
}

Fixed version (ground truth):
/** 
 * Release the lock if it's currently held by the calling thread. If the current thread does not hold the lock, and error will be thrown.
 */
public synchronized void release(){
  checkThread();
  thread=null;
  released=true;
}
Program: 3498
Project: 3498
Buggy source:
/** 
 * Acquire the lock if it's currently not acquired by another thread. If it's currently held by another thread, tryAcquire will return false, otherwise true is returned.
 * @return Returns true if the lock was acquired, false otherwise.
 */
public synchronized boolean tryAcquire(){
  if ((thread != null) && (thread != Thread.currentThread())) {
    return false;
  }
  thread=Thread.currentThread();
  return true;
}

Fixed version (ground truth):
/** 
 * Acquire the lock if it's currently not acquired by another thread. If it's currently held by another thread, tryAcquire will return false, otherwise true is returned.
 * @return Returns true if the lock was acquired, false otherwise.
 */
public synchronized boolean tryAcquire(){
  if ((thread != null) && (thread != Thread.currentThread())) {
    return false;
  }
  thread=Thread.currentThread();
  released=false;
  return true;
}
Program: 3499
Project: 3499
Buggy source:
/** 
 * Checks if the locker has access to the current thread. If the locker holds a different thread, than an Error is thrown.
 */
public void checkThread(){
  if ((thread != Thread.currentThread())) {
    throw new Error("String_Node_Str" + Thread.currentThread() + "String_Node_Str"+ thread);
  }
}

Fixed version (ground truth):
/** 
 * Checks if the locker has access to the current thread. If the locker holds a different thread, than an Error is thrown.
 */
public void checkThread(){
  if (released && thread == null) {
    throw new Error("String_Node_Str");
  }
  if ((thread != Thread.currentThread())) {
    throw new Error("String_Node_Str" + Thread.currentThread() + "String_Node_Str"+ thread);
  }
}
Program: 3500
Project: 3500
Buggy source:
/** 
 * Acquire the lock if it's currently not acquired by another thread. If it's currently held by another thread, an Error will be thrown.
 */
public synchronized void acquire(){
  if ((thread != null) && (thread != Thread.currentThread())) {
    throw new Error("String_Node_Str" + Thread.currentThread() + "String_Node_Str"+ thread);
  }
  thread=Thread.currentThread();
}

Fixed version (ground truth):
/** 
 * Acquire the lock if it's currently not acquired by another thread. If it's currently held by another thread, an Error will be thrown.
 */
public synchronized void acquire(){
  if ((thread != null) && (thread != Thread.currentThread())) {
    throw new Error("String_Node_Str" + Thread.currentThread() + "String_Node_Str"+ thread);
  }
  thread=Thread.currentThread();
  released=false;
}
Program: 3501
Project: 3501
Buggy source:
protected void acquireLock(){
  _acquireLock(getV8RuntimePtr());
}

Fixed version (ground truth):
protected void acquireLock(final long v8RuntimePtr){
  _acquireLock(v8RuntimePtr);
}
Program: 3502
Project: 3502
Buggy source:
protected void releaseLock(){
  _releaseLock(getV8RuntimePtr());
}

Fixed version (ground truth):
protected void releaseLock(final long v8RuntimePtr){
  _releaseLock(v8RuntimePtr);
}
Program: 3503
Project: 3503
Buggy source:
@Test(expected=IllegalStateException.class) public void testJ2V8CannotCreateRuntime(){
  V8.createV8Runtime();
}

Fixed version (ground truth):
@Test(expected=IllegalStateException.class) public void testJ2V8CannotCreateRuntime(){
  String oldValue=System.getProperty("String_Node_Str");
  System.setProperty("String_Node_Str","String_Node_Str");
  try {
    V8.createV8Runtime();
  }
  finally {
    System.setProperty("String_Node_Str",oldValue);
  }
}
Program: 3504
Project: 3504
Buggy source:
@Test public void testCreateIntegerMapFromV8Object(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,Object> map=V8ObjectUtils.toMap(object);
  assertEquals(3,map.size());
  assertEquals(1,map.get("String_Node_Str"));
  assertEquals(2,map.get("String_Node_Str"));
  assertEquals(3,map.get("String_Node_Str"));
  object.release();
}

Fixed version (ground truth):
@Test public void testCreateIntegerMapFromV8Object(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,? super Object> map=V8ObjectUtils.toMap(object);
  assertEquals(3,map.size());
  assertEquals(1,map.get("String_Node_Str"));
  assertEquals(2,map.get("String_Node_Str"));
  assertEquals(3,map.get("String_Node_Str"));
  object.release();
}
Program: 3505
Project: 3505
Buggy source:
@Test public void testCreateListFromV8Array(){
  V8Array array=v8.executeArrayScript("String_Node_Str");
  List<Object> list=V8ObjectUtils.toList(array);
  assertEquals(3,list.size());
  assertEquals(1,list.get(0));
  assertEquals(2,list.get(1));
  assertEquals(3,list.get(2));
  array.release();
}

Fixed version (ground truth):
@Test public void testCreateListFromV8Array(){
  V8Array array=v8.executeArrayScript("String_Node_Str");
  List<? super Object> list=V8ObjectUtils.toList(array);
  assertEquals(3,list.size());
  assertEquals(1,list.get(0));
  assertEquals(2,list.get(1));
  assertEquals(3,list.get(2));
  array.release();
}
Program: 3506
Project: 3506
Buggy source:
@Test public void testCreateListWithUndefinedFromV8Array(){
  V8Array array=v8.executeArrayScript("String_Node_Str");
  List<Object> list=V8ObjectUtils.toList(array);
  assertEquals(10,list.size());
  assertEquals(1,list.get(0));
  assertEquals(2,list.get(1));
  assertEquals(3,list.get(2));
  assertNull(list.get(3));
  assertNull(list.get(4));
  assertNull(list.get(5));
  assertNull(list.get(6));
  assertNull(list.get(7));
  assertNull(list.get(8));
  assertEquals(10,list.get(9));
  array.release();
}

Fixed version (ground truth):
@Test public void testCreateListWithUndefinedFromV8Array(){
  V8Array array=v8.executeArrayScript("String_Node_Str");
  List<? super Object> list=V8ObjectUtils.toList(array);
  assertEquals(10,list.size());
  assertEquals(1,list.get(0));
  assertEquals(2,list.get(1));
  assertEquals(3,list.get(2));
  assertNull(list.get(3));
  assertNull(list.get(4));
  assertNull(list.get(5));
  assertNull(list.get(6));
  assertNull(list.get(7));
  assertNull(list.get(8));
  assertEquals(10,list.get(9));
  array.release();
}
Program: 3507
Project: 3507
Buggy source:
@Test public void testCreateBooleanMapFromV8Object(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,Object> map=V8ObjectUtils.toMap(object);
  assertEquals(4,map.size());
  assertTrue((boolean)map.get("String_Node_Str"));
  assertTrue((boolean)map.get("String_Node_Str"));
  assertFalse((boolean)map.get("String_Node_Str"));
  assertFalse((boolean)map.get("String_Node_Str"));
  object.release();
}

Fixed version (ground truth):
@Test public void testCreateBooleanMapFromV8Object(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,? super Object> map=V8ObjectUtils.toMap(object);
  assertEquals(4,map.size());
  assertTrue((Boolean)map.get("String_Node_Str"));
  assertTrue((Boolean)map.get("String_Node_Str"));
  assertFalse((Boolean)map.get("String_Node_Str"));
  assertFalse((Boolean)map.get("String_Node_Str"));
  object.release();
}
Program: 3508
Project: 3508
Buggy source:
@Test public void testNullObjectGivesEmptyMap(){
  Map<String,Object> map=V8ObjectUtils.toMap(null);
  assertNotNull(map);
  assertEquals(0,map.size());
}

Fixed version (ground truth):
@Test public void testNullObjectGivesEmptyMap(){
  Map<String,? super Object> map=V8ObjectUtils.toMap(null);
  assertNotNull(map);
  assertEquals(0,map.size());
}
Program: 3509
Project: 3509
Buggy source:
@SuppressWarnings("String_Node_Str") @Test public void testCreateMatrixFromV8Array(){
  V8Array array=v8.executeArrayScript("String_Node_Str");
  List<Object> list=V8ObjectUtils.toList(array);
  assertEquals(3,list.size());
  assertEquals(3,((List)list.get(0)).size());
  assertEquals(3,((List)list.get(1)).size());
  assertEquals(3,((List)list.get(2)).size());
  assertEquals(1,((List)list.get(0)).get(0));
  assertEquals(2,((List)list.get(0)).get(1));
  assertEquals(3,((List)list.get(0)).get(2));
  assertTrue((boolean)((List)list.get(1)).get(0));
  assertFalse((boolean)((List)list.get(1)).get(1));
  assertTrue((boolean)((List)list.get(1)).get(2));
  assertEquals("String_Node_Str",((List)list.get(2)).get(0));
  assertEquals("String_Node_Str",((List)list.get(2)).get(1));
  assertEquals("String_Node_Str",((List)list.get(2)).get(2));
  array.release();
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") @Test public void testCreateMatrixFromV8Array(){
  V8Array array=v8.executeArrayScript("String_Node_Str");
  List<? super Object> list=V8ObjectUtils.toList(array);
  assertEquals(3,list.size());
  assertEquals(3,((List)list.get(0)).size());
  assertEquals(3,((List)list.get(1)).size());
  assertEquals(3,((List)list.get(2)).size());
  assertEquals(1,((List)list.get(0)).get(0));
  assertEquals(2,((List)list.get(0)).get(1));
  assertEquals(3,((List)list.get(0)).get(2));
  assertTrue((Boolean)((List)list.get(1)).get(0));
  assertFalse((Boolean)((List)list.get(1)).get(1));
  assertTrue((Boolean)((List)list.get(1)).get(2));
  assertEquals("String_Node_Str",((List)list.get(2)).get(0));
  assertEquals("String_Node_Str",((List)list.get(2)).get(1));
  assertEquals("String_Node_Str",((List)list.get(2)).get(2));
  array.release();
}
Program: 3510
Project: 3510
Buggy source:
@Test public void testCreateMixedMapFromV8Object(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,Object> map=V8ObjectUtils.toMap(object);
  assertEquals(4,map.size());
  assertTrue((boolean)map.get("String_Node_Str"));
  assertEquals(1,(int)map.get("String_Node_Str"));
  assertEquals(3.14159,(double)map.get("String_Node_Str"),0.0000001);
  assertEquals("String_Node_Str",map.get("String_Node_Str"));
  object.release();
}

Fixed version (ground truth):
@Test public void testCreateMixedMapFromV8Object(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,? super Object> map=V8ObjectUtils.toMap(object);
  assertEquals(4,map.size());
  assertTrue((Boolean)map.get("String_Node_Str"));
  assertEquals(1,(int)(Integer)map.get("String_Node_Str"));
  assertEquals(3.14159,(Double)map.get("String_Node_Str"),0.0000001);
  assertEquals("String_Node_Str",map.get("String_Node_Str"));
  object.release();
}
Program: 3511
Project: 3511
Buggy source:
@Test public void testCreateStringMapFromV8Object(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,Object> map=V8ObjectUtils.toMap(object);
  assertEquals(4,map.size());
  assertEquals("String_Node_Str",map.get("String_Node_Str"));
  assertEquals("String_Node_Str",map.get("String_Node_Str"));
  assertEquals("String_Node_Str",map.get("String_Node_Str"));
  assertEquals("String_Node_Str",map.get("String_Node_Str"));
  object.release();
}

Fixed version (ground truth):
@Test public void testCreateStringMapFromV8Object(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,? super Object> map=V8ObjectUtils.toMap(object);
  assertEquals(4,map.size());
  assertEquals("String_Node_Str",map.get("String_Node_Str"));
  assertEquals("String_Node_Str",map.get("String_Node_Str"));
  assertEquals("String_Node_Str",map.get("String_Node_Str"));
  assertEquals("String_Node_Str",map.get("String_Node_Str"));
  object.release();
}
Program: 3512
Project: 3512
Buggy source:
@SuppressWarnings("String_Node_Str") @Test public void testCreateMapWithLists(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,Object> map=V8ObjectUtils.toMap(object);
  assertEquals(2,map.size());
  assertEquals(1,((List)map.get("String_Node_Str")).get(0));
  assertEquals(2,((List)map.get("String_Node_Str")).get(1));
  assertEquals(3,((List)map.get("String_Node_Str")).get(2));
  assertEquals(4,((List)map.get("String_Node_Str")).get(0));
  assertEquals(5,((List)map.get("String_Node_Str")).get(1));
  assertEquals(6,((List)map.get("String_Node_Str")).get(2));
  object.release();
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") @Test public void testCreateMapWithLists(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,? super Object> map=V8ObjectUtils.toMap(object);
  assertEquals(2,map.size());
  assertEquals(1,((List)map.get("String_Node_Str")).get(0));
  assertEquals(2,((List)map.get("String_Node_Str")).get(1));
  assertEquals(3,((List)map.get("String_Node_Str")).get(2));
  assertEquals(4,((List)map.get("String_Node_Str")).get(0));
  assertEquals(5,((List)map.get("String_Node_Str")).get(1));
  assertEquals(6,((List)map.get("String_Node_Str")).get(2));
  object.release();
}
Program: 3513
Project: 3513
Buggy source:
@Test public void testCreateMapWithNulls(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,Object> map=V8ObjectUtils.toMap(object);
  assertEquals(1,map.size());
  assertNull(map.get(0));
  object.release();
}

Fixed version (ground truth):
@Test public void testCreateMapWithNulls(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,? super Object> map=V8ObjectUtils.toMap(object);
  assertEquals(1,map.size());
  assertNull(map.get(0));
  object.release();
}
Program: 3514
Project: 3514
Buggy source:
@Test public void testNullArrayGivesEmptyMap(){
  List<Object> list=V8ObjectUtils.toList(null);
  assertNotNull(list);
  assertEquals(0,list.size());
}

Fixed version (ground truth):
@Test public void testNullArrayGivesEmptyMap(){
  List<? super Object> list=V8ObjectUtils.toList(null);
  assertNotNull(list);
  assertEquals(0,list.size());
}
Program: 3515
Project: 3515
Buggy source:
@Test public void testCreateListWithNullFromV8Array(){
  V8Array array=v8.executeArrayScript("String_Node_Str");
  List<Object> list=V8ObjectUtils.toList(array);
  assertEquals(1,list.size());
  assertNull(list.get(0));
  array.release();
}

Fixed version (ground truth):
@Test public void testCreateListWithNullFromV8Array(){
  V8Array array=v8.executeArrayScript("String_Node_Str");
  List<? super Object> list=V8ObjectUtils.toList(array);
  assertEquals(1,list.size());
  assertNull(list.get(0));
  array.release();
}
Program: 3516
Project: 3516
Buggy source:
@Test public void testCreateDoubleMapFromV8Object(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,Object> map=V8ObjectUtils.toMap(object);
  assertEquals(4,map.size());
  assertEquals(1.1,(double)map.get("String_Node_Str"),0.000001);
  assertEquals(2.2,(double)map.get("String_Node_Str"),0.000001);
  assertEquals(3.3,(double)map.get("String_Node_Str"),0.000001);
  assertEquals(4.4,(double)map.get("String_Node_Str"),0.000001);
  object.release();
}

Fixed version (ground truth):
@Test public void testCreateDoubleMapFromV8Object(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,? super Object> map=V8ObjectUtils.toMap(object);
  assertEquals(4,map.size());
  assertEquals(1.1,(Double)map.get("String_Node_Str"),0.000001);
  assertEquals(2.2,(Double)map.get("String_Node_Str"),0.000001);
  assertEquals(3.3,(Double)map.get("String_Node_Str"),0.000001);
  assertEquals(4.4,(Double)map.get("String_Node_Str"),0.000001);
  object.release();
}
Program: 3517
Project: 3517
Buggy source:
@SuppressWarnings("String_Node_Str") @Test public void testCreateNestedMapFromV8Object(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,Object> map=V8ObjectUtils.toMap(object);
  assertEquals(2,map.size());
  assertEquals(7,map.get("String_Node_Str"));
  assertEquals("String_Node_Str",((Map)map.get("String_Node_Str")).get("String_Node_Str"));
  assertEquals("String_Node_Str",((Map)map.get("String_Node_Str")).get("String_Node_Str"));
  object.release();
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") @Test public void testCreateNestedMapFromV8Object(){
  V8Object object=v8.executeObjectScript("String_Node_Str");
  Map<String,? super Object> map=V8ObjectUtils.toMap(object);
  assertEquals(2,map.size());
  assertEquals(7,map.get("String_Node_Str"));
  assertEquals("String_Node_Str",((Map)map.get("String_Node_Str")).get("String_Node_Str"));
  assertEquals("String_Node_Str",((Map)map.get("String_Node_Str")).get("String_Node_Str"));
  object.release();
}
Program: 3518
Project: 3518
Buggy source:
/** 
 * Array Function 
 */
@Test public void testSimpleArrayFunction(){
  v8.executeVoidScript("String_Node_Str");
  V8Array result=v8.executeArrayFunction("String_Node_Str",null);
  assertEquals(3,result.getSize());
  result.release();
}

Fixed version (ground truth):
/** 
 * Array Function 
 */
@Test public void testSimpleArrayFunction(){
  v8.executeVoidScript("String_Node_Str");
  V8Array result=v8.executeArrayFunction("String_Node_Str",null);
  assertEquals(3,result.length());
  result.release();
}
Program: 3520
Project: 3520
Buggy source:
@Override public int scrollHorizontallyBy(int dx,RecyclerView.Recycler recycler,RecyclerView.State state){
  if (getChildCount() == 0) {
    return 0;
  }
  final View topView=getChildAt(0);
  final View bottomView=getChildAt(mVisibleColumnCount - 1);
  int viewSpan=getDecoratedRight(bottomView) - getDecoratedLeft(topView);
  if (viewSpan <= getHorizontalSpace()) {
    return 0;
  }
  int delta;
  boolean leftBoundReached=getFirstVisibleColumn() == 0;
  boolean rightBoundReached=getLastVisibleColumn() >= getTotalColumnCount();
  if (dx > 0) {
    if (rightBoundReached) {
      int rightOffset=getHorizontalSpace() - getDecoratedRight(bottomView) + getPaddingRight();
      delta=Math.max(-dx,rightOffset);
    }
 else {
      delta=-dx;
    }
  }
 else {
    if (leftBoundReached) {
      int leftOffset=-getDecoratedLeft(topView) + getPaddingLeft();
      delta=Math.min(-dx,leftOffset);
    }
 else {
      delta=-dx;
    }
  }
  offsetChildrenHorizontal(delta);
  if (dx > 0) {
    if (getDecoratedRight(topView) < 0 && !rightBoundReached) {
      fillGrid(DIRECTION_END,recycler);
    }
 else     if (!rightBoundReached) {
      fillGrid(DIRECTION_NONE,recycler);
    }
  }
 else {
    if (getDecoratedLeft(topView) > 0 && !leftBoundReached) {
      fillGrid(DIRECTION_START,recycler);
    }
 else     if (!leftBoundReached) {
      fillGrid(DIRECTION_NONE,recycler);
    }
  }
  return -delta;
}

Fixed version (ground truth):
@Override public int scrollHorizontallyBy(int dx,RecyclerView.Recycler recycler,RecyclerView.State state){
  if (getChildCount() == 0) {
    return 0;
  }
  final View topView=getChildAt(0);
  final View bottomView=getChildAt(mVisibleColumnCount - 1);
  int viewSpan=getDecoratedRight(bottomView) - getDecoratedLeft(topView);
  if (viewSpan < getHorizontalSpace()) {
    return 0;
  }
  int delta;
  boolean leftBoundReached=getFirstVisibleColumn() == 0;
  boolean rightBoundReached=getLastVisibleColumn() >= getTotalColumnCount();
  if (dx > 0) {
    if (rightBoundReached) {
      int rightOffset=getHorizontalSpace() - getDecoratedRight(bottomView) + getPaddingRight();
      delta=Math.max(-dx,rightOffset);
    }
 else {
      delta=-dx;
    }
  }
 else {
    if (leftBoundReached) {
      int leftOffset=-getDecoratedLeft(topView) + getPaddingLeft();
      delta=Math.min(-dx,leftOffset);
    }
 else {
      delta=-dx;
    }
  }
  offsetChildrenHorizontal(delta);
  if (dx > 0) {
    if (getDecoratedRight(topView) < 0 && !rightBoundReached) {
      fillGrid(DIRECTION_END,recycler);
    }
 else     if (!rightBoundReached) {
      fillGrid(DIRECTION_NONE,recycler);
    }
  }
 else {
    if (getDecoratedLeft(topView) > 0 && !leftBoundReached) {
      fillGrid(DIRECTION_START,recycler);
    }
 else     if (!leftBoundReached) {
      fillGrid(DIRECTION_NONE,recycler);
    }
  }
  return -delta;
}
Program: 3521
Project: 3521
Buggy source:
private int getTotalRowCount(){
  int maxRow=getItemCount() / mTotalColumnCount;
  if (getItemCount() % mTotalColumnCount != 0) {
    maxRow++;
  }
  return maxRow;
}

Fixed version (ground truth):
private int getTotalRowCount(){
  if (getItemCount() == 0 || mTotalColumnCount == 0) {
    return 0;
  }
  int maxRow=getItemCount() / mTotalColumnCount;
  if (getItemCount() % mTotalColumnCount != 0) {
    maxRow++;
  }
  return maxRow;
}
Program: 3525
Project: 3525
Buggy source:
/** 
 * Constructor.
 * @param table The table for which to get find a primary key.
 * @throws SQLException
 */
public PrimaryKeyFinder(String table) throws SQLException {
  this.table=table;
  if (table == null || table.trim().length() == 0) {
    throw new SQLException("String_Node_Str" + this.table + "String_Node_Str");
  }
  Statement stat=null;
  ResultSet rs=null;
  try {
    stat=conn.createStatement();
    rs=stat.executeQuery("String_Node_Str" + "String_Node_Str" + escape(table) + "String_Node_Str");
    if (!rs.next())     throw new SQLException("String_Node_Str" + table + "String_Node_Str");
    Matcher matcher=PK_NAMED_PATTERN.matcher(rs.getString(1));
    if (matcher.find()) {
      pkName='\'' + escape(matcher.group(1).toLowerCase()) + '\'';
      pkColumns=matcher.group(2).split("String_Node_Str");
    }
 else {
      matcher=PK_UNNAMED_PATTERN.matcher(rs.getString(1));
      if (matcher.find()) {
        pkColumns=matcher.group(1).split("String_Node_Str");
      }
    }
    if (pkColumns == null) {
      rs=stat.executeQuery("String_Node_Str" + escape(table) + "String_Node_Str");
      while (rs.next()) {
        if (rs.getBoolean(6))         pkColumns=new String[]{rs.getString(2)};
      }
    }
    if (pkColumns != null)     for (int i=0; i < pkColumns.length; i++) {
      pkColumns[i]=pkColumns[i].toLowerCase().trim();
    }
  }
  finally {
    try {
      if (rs != null)       rs.close();
    }
 catch (    Exception e) {
    }
    try {
      if (stat != null)       stat.close();
    }
 catch (    Exception e) {
    }
  }
}

Fixed version (ground truth):
/** 
 * Constructor.
 * @param table The table for which to get find a primary key.
 * @throws SQLException
 */
public PrimaryKeyFinder(String table) throws SQLException {
  this.table=table;
  if (table == null || table.trim().length() == 0) {
    throw new SQLException("String_Node_Str" + this.table + "String_Node_Str");
  }
  Statement stat=null;
  ResultSet rs=null;
  try {
    stat=conn.createStatement();
    rs=stat.executeQuery("String_Node_Str" + "String_Node_Str" + escape(table) + "String_Node_Str");
    if (!rs.next())     throw new SQLException("String_Node_Str" + table + "String_Node_Str");
    Matcher matcher=PK_NAMED_PATTERN.matcher(rs.getString(1));
    if (matcher.find()) {
      pkName='\'' + escape(matcher.group(1)) + '\'';
      pkColumns=matcher.group(2).split("String_Node_Str");
    }
 else {
      matcher=PK_UNNAMED_PATTERN.matcher(rs.getString(1));
      if (matcher.find()) {
        pkColumns=matcher.group(1).split("String_Node_Str");
      }
    }
    if (pkColumns == null) {
      rs=stat.executeQuery("String_Node_Str" + escape(table) + "String_Node_Str");
      while (rs.next()) {
        if (rs.getBoolean(6))         pkColumns=new String[]{rs.getString(2)};
      }
    }
    if (pkColumns != null)     for (int i=0; i < pkColumns.length; i++) {
      pkColumns[i]=pkColumns[i].trim();
    }
  }
  finally {
    try {
      if (rs != null)       rs.close();
    }
 catch (    Exception e) {
    }
    try {
      if (stat != null)       stat.close();
    }
 catch (    Exception e) {
    }
  }
}