Program: 85930
Project: 85930
Buggy source:
/** 
 * Calculates a signature hash, that is, a hash of a simplified form of the transaction. How exactly the transaction is simplified is specified by the type and anyoneCanPay parameters.<p> You don't normally ever need to call this yourself. It will become more useful in future as the contracts features of Bitcoin are developed.
 * @param inputIndex input the signature is being calculated for. Tx signatures are always relative to an input.
 * @param connectedScript the bytes that should be in the given input during signing.
 * @param type Should be SigHash.ALL
 * @param anyoneCanPay should be false.
 */
public synchronized Sha256Hash hashTransactionForSignature(int inputIndex,byte[] connectedScript,SigHash type,boolean anyoneCanPay){
  try {
    byte[][] scripts=new byte[inputs.size()][];
    for (int i=0; i < inputs.size(); i++) {
      scripts[i]=inputs.get(i).getScriptBytes();
      inputs.get(i).setScriptBytes(TransactionInput.EMPTY_ARRAY);
    }
    TransactionInput input=inputs.get(inputIndex);
    input.setScriptBytes(connectedScript);
    ByteArrayOutputStream bos=new UnsafeByteArrayOutputStream(length == UNKNOWN_LENGTH ? 256 : length + 4);
    bitcoinSerialize(bos);
    int hashType=type.ordinal() + 1;
    if (anyoneCanPay)     hashType|=0x80;
    uint32ToByteStreamLE(hashType,bos);
    Sha256Hash hash=new Sha256Hash(doubleDigest(bos.toByteArray()));
    for (int i=0; i < inputs.size(); i++) {
      inputs.get(i).setScriptBytes(scripts[i]);
    }
    return hash;
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
/** 
 * Calculates a signature hash, that is, a hash of a simplified form of the transaction. How exactly the transaction is simplified is specified by the type and anyoneCanPay parameters.<p> You don't normally ever need to call this yourself. It will become more useful in future as the contracts features of Bitcoin are developed.
 * @param inputIndex input the signature is being calculated for. Tx signatures are always relative to an input.
 * @param connectedScript the bytes that should be in the given input during signing.
 * @param type Should be SigHash.ALL
 * @param anyoneCanPay should be false.
 */
public synchronized Sha256Hash hashTransactionForSignature(int inputIndex,byte[] connectedScript,SigHash type,boolean anyoneCanPay){
  try {
    byte[][] scripts=new byte[inputs.size()][];
    for (int i=0; i < inputs.size(); i++) {
      scripts[i]=inputs.get(i).getScriptBytes();
      inputs.get(i).setScriptBytes(TransactionInput.EMPTY_ARRAY);
    }
    TransactionInput input=inputs.get(inputIndex);
    input.setScriptBytes(connectedScript);
    ByteArrayOutputStream bos=new UnsafeByteArrayOutputStream(length == UNKNOWN_LENGTH ? 256 : length + 4);
    bitcoinSerialize(bos);
    int hashType=type.ordinal() + 1;
    if (anyoneCanPay)     hashType|=0x80;
    uint32ToByteStreamLE(hashType,bos);
    Sha256Hash hash=new Sha256Hash(doubleDigest(bos.toByteArray()));
    bos.close();
    for (int i=0; i < inputs.size(); i++) {
      inputs.get(i).setScriptBytes(scripts[i]);
    }
    return hash;
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}