Program: 35132
Project: 35132
Buggy source:
@Override public CoinData createByTransferData(Transaction tx,CoinTransferData coinParam,String password) throws NulsException {
  lock.lock();
  try {
    UtxoData utxoData=new UtxoData();
    List<UtxoInput> inputs=new ArrayList<>();
    List<UtxoOutput> outputs=new ArrayList<>();
    if (coinParam.getTotalNa().equals(Na.ZERO)) {
      utxoData.setInputs(inputs);
      utxoData.setOutputs(outputs);
      return utxoData;
    }
    long inputValue=0;
    if (!coinParam.getFrom().isEmpty()) {
      Na totalFee=Na.ZERO;
      if (tx instanceof UnlockNulsTransaction) {
        totalFee=coinParam.getFee();
      }
 else {
        totalFee=coinParam.getTotalNa().add(coinParam.getFee());
      }
      List<UtxoOutput> unSpends=coinManager.getAccountsUnSpend(coinParam.getFrom(),totalFee);
      if (unSpends.isEmpty()) {
        throw new NulsException(ErrorCode.BALANCE_NOT_ENOUGH);
      }
      for (int i=0; i < unSpends.size(); i++) {
        UtxoOutput output=unSpends.get(i);
        UtxoInput input=new UtxoInput();
        input.setFrom(output);
        input.setFromHash(output.getTxHash());
        input.setFromIndex(output.getIndex());
        input.setTxHash(tx.getHash());
        input.setIndex(i);
        inputValue+=output.getValue();
        inputs.add(input);
      }
    }
    Account account=null;
    byte[] priKey=null;
    if (coinParam.getPriKey() != null) {
      priKey=coinParam.getPriKey();
    }
 else     if (!coinParam.getFrom().isEmpty()) {
      account=accountService.getAccount(coinParam.getFrom().get(0));
      if (account == null) {
        throw new NulsException(ErrorCode.ACCOUNT_NOT_EXIST);
      }
      if (account.isEncrypted() && account.isLocked()) {
        if (!account.unlock(password)) {
          throw new NulsException(ErrorCode.PASSWORD_IS_WRONG);
        }
        priKey=account.getPriKey();
        account.lock();
      }
 else {
        priKey=account.getPriKey();
      }
    }
    int i=0;
    long outputValue=0;
    for (    Map.Entry<String,List<Coin>> entry : coinParam.getToMap().entrySet()) {
      String address=entry.getKey();
      List<Coin> coinList=entry.getValue();
      for (      Coin coin : coinList) {
        UtxoOutput output=new UtxoOutput();
        output.setAddress(address);
        output.setValue(coin.getNa().getValue());
        if (output.getLockTime() > 0) {
          output.setStatus(OutPutStatusEnum.UTXO_UNCONFIRM_TIME_LOCK);
        }
 else         if (tx instanceof LockNulsTransaction) {
          output.setStatus(OutPutStatusEnum.UTXO_UNCONFIRM_CONSENSUS_LOCK);
        }
 else {
          output.setStatus(OutPutStatusEnum.UTXO_UNCONFIRM_UNSPEND);
        }
        output.setIndex(i);
        P2PKHScript p2PKHScript=new P2PKHScript(new NulsDigestData(NulsDigestData.DIGEST_ALG_SHA160,new Address(address).getHash160()));
        output.setP2PKHScript(p2PKHScript);
        if (coin.getUnlockHeight() > 0) {
          output.setLockTime(coin.getUnlockHeight());
        }
 else         if (coin.getUnlockTime() > 0) {
          output.setLockTime(coin.getUnlockTime());
        }
 else {
          output.setLockTime(0L);
        }
        output.setTxHash(tx.getHash());
        outputValue+=output.getValue();
        outputs.add(output);
        i++;
      }
    }
    long balance=0;
    if (outputValue > 0) {
      balance=inputValue - outputValue - coinParam.getFee().getValue();
    }
 else {
      balance=inputValue - coinParam.getTotalNa().getValue() - coinParam.getFee().getValue();
    }
    if (balance > 0) {
      UtxoOutput output=new UtxoOutput();
      output.setAddress(inputs.get(0).getFrom().getAddress());
      output.setValue(balance);
      output.setIndex(i);
      output.setTxHash(tx.getHash());
      output.setStatus(OutPutStatusEnum.UTXO_UNCONFIRM_UNSPEND);
      P2PKHScript p2PKHScript=new P2PKHScript(new NulsDigestData(NulsDigestData.DIGEST_ALG_SHA160,account.getHash160()));
      output.setP2PKHScript(p2PKHScript);
      outputs.add(output);
    }
    utxoData.setInputs(inputs);
    utxoData.setOutputs(outputs);
    return utxoData;
  }
  finally {
    lock.unlock();
  }
}

Fixed version (ground truth):
@Override public CoinData createByTransferData(Transaction tx,CoinTransferData coinParam,String password) throws NulsException {
  lock.lock();
  try {
    UtxoData utxoData=new UtxoData();
    List<UtxoInput> inputs=new ArrayList<>();
    List<UtxoOutput> outputs=new ArrayList<>();
    if (coinParam.getTotalNa().equals(Na.ZERO)) {
      utxoData.setInputs(inputs);
      utxoData.setOutputs(outputs);
      return utxoData;
    }
    long inputValue=0;
    if (!coinParam.getFrom().isEmpty()) {
      Na totalFee=Na.ZERO;
      if (tx instanceof UnlockNulsTransaction) {
        totalFee=coinParam.getFee();
      }
 else {
        totalFee=coinParam.getTotalNa().add(coinParam.getFee());
      }
      List<UtxoOutput> unSpends=coinManager.getAccountsUnSpend(coinParam.getFrom(),totalFee);
      if (unSpends.isEmpty()) {
        throw new NulsException(ErrorCode.BALANCE_NOT_ENOUGH);
      }
      for (int i=0; i < unSpends.size(); i++) {
        UtxoOutput output=unSpends.get(i);
        UtxoInput input=new UtxoInput();
        input.setFrom(output);
        input.setFromHash(output.getTxHash());
        input.setFromIndex(output.getIndex());
        input.setTxHash(tx.getHash());
        input.setIndex(i);
        inputValue+=output.getValue();
        inputs.add(input);
      }
    }
    Account account=null;
    byte[] priKey=null;
    if (coinParam.getPriKey() != null) {
      priKey=coinParam.getPriKey();
    }
 else     if (!coinParam.getFrom().isEmpty()) {
      account=accountService.getAccount(coinParam.getFrom().get(0));
      if (account == null) {
        throw new NulsException(ErrorCode.ACCOUNT_NOT_EXIST);
      }
      if (account.isEncrypted() && account.isLocked()) {
        if (!account.unlock(password)) {
          throw new NulsException(ErrorCode.PASSWORD_IS_WRONG);
        }
        priKey=account.getPriKey();
        account.lock();
      }
 else {
        priKey=account.getPriKey();
      }
    }
    int i=0;
    long outputValue=0;
    for (    Map.Entry<String,List<Coin>> entry : coinParam.getToMap().entrySet()) {
      String address=entry.getKey();
      List<Coin> coinList=entry.getValue();
      for (      Coin coin : coinList) {
        UtxoOutput output=new UtxoOutput();
        output.setAddress(address);
        output.setValue(coin.getNa().getValue());
        if (output.getLockTime() > 0) {
          output.setStatus(OutPutStatusEnum.UTXO_UNCONFIRMED_TIME_LOCK);
        }
 else         if (tx instanceof LockNulsTransaction) {
          output.setStatus(OutPutStatusEnum.UTXO_UNCONFIRMED_CONSENSUS_LOCK);
        }
 else {
          output.setStatus(OutPutStatusEnum.UTXO_UNCONFIRMED_UNSPENT);
        }
        output.setIndex(i);
        P2PKHScript p2PKHScript=new P2PKHScript(new NulsDigestData(NulsDigestData.DIGEST_ALG_SHA160,new Address(address).getHash160()));
        output.setP2PKHScript(p2PKHScript);
        if (coin.getUnlockHeight() > 0) {
          output.setLockTime(coin.getUnlockHeight());
        }
 else         if (coin.getUnlockTime() > 0) {
          output.setLockTime(coin.getUnlockTime());
        }
 else {
          output.setLockTime(0L);
        }
        output.setTxHash(tx.getHash());
        outputValue+=output.getValue();
        outputs.add(output);
        i++;
      }
    }
    long balance=0;
    if (outputValue > 0) {
      balance=inputValue - outputValue - coinParam.getFee().getValue();
    }
 else {
      balance=inputValue - coinParam.getTotalNa().getValue() - coinParam.getFee().getValue();
    }
    if (balance > 0) {
      UtxoOutput output=new UtxoOutput();
      output.setAddress(inputs.get(0).getFrom().getAddress());
      output.setValue(balance);
      output.setIndex(i);
      output.setTxHash(tx.getHash());
      output.setStatus(OutPutStatusEnum.UTXO_UNCONFIRMED_UNSPENT);
      P2PKHScript p2PKHScript=new P2PKHScript(new NulsDigestData(NulsDigestData.DIGEST_ALG_SHA160,account.getHash160()));
      output.setP2PKHScript(p2PKHScript);
      outputs.add(output);
    }
    utxoData.setInputs(inputs);
    utxoData.setOutputs(outputs);
    return utxoData;
  }
  finally {
    lock.unlock();
  }
}