Program: 82233
Project: 82233
Buggy source:
/** 
 * Compares this   {@code BigDecimal} with {@code val}. Returns one of the three values   {@code 1},   {@code 0}, or   {@code -1}. The method behaves as if  {@code this.subtract(val)} is computed. If this difference is > 0 then 1 isreturned, if the difference is < 0 then -1 is returned, and if the difference is 0 then 0 is returned. This means, that if two decimal instances are compared which are equal in value but differ in scale, then these two instances are considered as equal.
 * @param val value to be compared with {@code this}.
 * @return {@code 1} if {@code this > val},   {@code -1} if {@code this < val},  {@code 0} if {@code this == val}.
 * @throws NullPointerException if {@code val == null}.
 */
public int compareTo(BigDecimal val){
  int thisSign=signum();
  int valueSign=val.signum();
  if (thisSign == valueSign) {
    if (this.scale == val.scale && this.bitLength < 54 && val.bitLength < 54) {
      return (smallValue < val.smallValue) ? -1 : (smallValue > val.smallValue) ? 1 : 0;
    }
    double diffScale=this.scale - val.scale;
    double diffPrecision=this.approxPrecision() - val.approxPrecision();
    if (diffPrecision > diffScale + 1) {
      return thisSign;
    }
 else     if (diffPrecision < diffScale - 1) {
      return -thisSign;
    }
 else {
      BigInteger thisUnscaled=this.getUnscaledValue();
      BigInteger valUnscaled=val.getUnscaledValue();
      if (diffScale < 0) {
        thisUnscaled=thisUnscaled.multiply(Multiplication.powerOf10(-diffScale));
      }
 else       if (diffScale > 0) {
        valUnscaled=valUnscaled.multiply(Multiplication.powerOf10(diffScale));
      }
      return thisUnscaled.compareTo(valUnscaled);
    }
  }
 else   if (thisSign < valueSign) {
    return -1;
  }
 else {
    return 1;
  }
}

Fixed version (ground truth):
/** 
 * Compares this   {@code BigDecimal} with {@code val}. Returns one of the three values   {@code 1},   {@code 0}, or   {@code -1}. The method behaves as if  {@code this.subtract(val)} is computed. If this difference is > 0 then 1 isreturned, if the difference is < 0 then -1 is returned, and if the difference is 0 then 0 is returned. This means, that if two decimal instances are compared which are equal in value but differ in scale, then these two instances are considered as equal.
 * @param val value to be compared with {@code this}.
 * @return {@code 1} if {@code this > val},   {@code -1} if {@code this < val},  {@code 0} if {@code this == val}.
 * @throws NullPointerException if {@code val == null}.
 */
public int compareTo(BigDecimal val){
  int thisSign=signum();
  int valueSign=val.signum();
  if (thisSign == valueSign) {
    if (this.scale == val.scale && this.bitLength < SMALL_VALUE_BITS && val.bitLength < SMALL_VALUE_BITS) {
      return (smallValue < val.smallValue) ? -1 : (smallValue > val.smallValue) ? 1 : 0;
    }
    double diffScale=this.scale - val.scale;
    double diffPrecision=this.approxPrecision() - val.approxPrecision();
    if (diffPrecision > diffScale + 1) {
      return thisSign;
    }
 else     if (diffPrecision < diffScale - 1) {
      return -thisSign;
    }
 else {
      BigInteger thisUnscaled=this.getUnscaledValue();
      BigInteger valUnscaled=val.getUnscaledValue();
      if (diffScale < 0) {
        thisUnscaled=thisUnscaled.multiply(Multiplication.powerOf10(-diffScale));
      }
 else       if (diffScale > 0) {
        valUnscaled=valUnscaled.multiply(Multiplication.powerOf10(diffScale));
      }
      return thisUnscaled.compareTo(valUnscaled);
    }
  }
 else   if (thisSign < valueSign) {
    return -1;
  }
 else {
    return 1;
  }
}