Program: 34971
Project: 34971
Buggy source:
@Override public CoinDataResult getCoinData(byte[] address,Na amount,int size,Na price) throws NulsException {
  if (null == price) {
    throw new NulsRuntimeException(KernelErrorCode.PARAMETER_ERROR);
  }
  lock.lock();
  try {
    CoinDataResult coinDataResult=new CoinDataResult();
    List<Coin> coinList=balanceManager.getCoinListByAddress(address);
    if (coinList.isEmpty()) {
      coinDataResult.setEnough(false);
      return coinDataResult;
    }
    Collections.sort(coinList,CoinComparator.getInstance());
    boolean enough=false;
    List<Coin> coins=new ArrayList<>();
    Na values=Na.ZERO;
    for (int i=0; i < coinList.size(); i++) {
      Coin coin=coinList.get(i);
      if (!coin.usable()) {
        continue;
      }
      if (coin.getNa().equals(Na.ZERO)) {
        continue;
      }
      coins.add(coin);
      size+=coin.size();
      if (i == 127) {
        size+=1;
      }
      Na fee=TransactionFeeCalculator.getFee(size,price);
      values=values.add(coin.getNa());
      if (values.isGreaterOrEquals(amount.add(fee))) {
        Na change=values.subtract(amount.add(fee));
        if (change.isGreaterThan(Na.ZERO)) {
          Coin changeCoin=new Coin();
          changeCoin.setOwner(address);
          changeCoin.setNa(change);
          fee=TransactionFeeCalculator.getFee(size + changeCoin.size(),price);
          if (values.isLessThan(amount.add(fee))) {
            continue;
          }
          coinDataResult.setChange(changeCoin);
        }
        enough=true;
        coinDataResult.setEnough(true);
        coinDataResult.setFee(fee);
        coinDataResult.setCoinList(coins);
        break;
      }
    }
    if (!enough) {
      coinDataResult.setEnough(false);
      return coinDataResult;
    }
    return coinDataResult;
  }
  finally {
    lock.unlock();
  }
}

Fixed version (ground truth):
@Override public CoinDataResult getCoinData(byte[] address,Na amount,int size,Na price) throws NulsException {
  if (null == price) {
    throw new NulsRuntimeException(KernelErrorCode.PARAMETER_ERROR);
  }
  lock.lock();
  try {
    CoinDataResult coinDataResult=new CoinDataResult();
    List<Coin> coinList=balanceManager.getCoinListByAddress(address);
    if (coinList.isEmpty()) {
      coinDataResult.setEnough(false);
      return coinDataResult;
    }
    Collections.sort(coinList,CoinComparator.getInstance());
    boolean enough=false;
    List<Coin> coins=new ArrayList<>();
    Na values=Na.ZERO;
    for (int i=0; i < coinList.size(); i++) {
      Coin coin=coinList.get(i);
      if (!coin.usable()) {
        continue;
      }
      if (coin.getNa().equals(Na.ZERO)) {
        continue;
      }
      coins.add(coin);
      size+=coin.size();
      if (i == 127) {
        size+=1;
      }
      Na fee=TransactionFeeCalculator.getFee(size,price);
      values=values.add(coin.getNa());
      if (values.isGreaterThan(amount.add(fee))) {
        Na change=values.subtract(amount.add(fee));
        Coin changeCoin=new Coin();
        changeCoin.setOwner(address);
        changeCoin.setNa(change);
        fee=TransactionFeeCalculator.getFee(size + changeCoin.size(),price);
        if (values.isLessThan(amount.add(fee))) {
          continue;
        }
        coinDataResult.setChange(changeCoin);
      }
      coinDataResult.setFee(fee);
      if (values.isGreaterOrEquals(amount.add(fee))) {
        enough=true;
        coinDataResult.setEnough(true);
        break;
      }
    }
    coinDataResult.setCoinList(coins);
    if (!enough) {
      coinDataResult.setEnough(false);
      return coinDataResult;
    }
    return coinDataResult;
  }
  finally {
    lock.unlock();
  }
}