Program: 85622
Project: 85622
Buggy source:
public void testBlock(byte[] blockBytes,boolean isChild,boolean lazy,boolean retain) throws Exception {
  BitcoinSerializer bsRef=new BitcoinSerializer(unitTestParams,false,false);
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  BitcoinSerializer bs=new BitcoinSerializer(unitTestParams,lazy,retain);
  Block b1;
  Block bRef;
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  bos.reset();
  bsRef.serialize(bRef,bos);
  assertTrue(Arrays.equals(bos.toByteArray(),blockBytes));
  assertEquals(!lazy,b1.isParsedTransactions());
  assertEquals(!lazy,b1.isParsedHeader());
  if (b1.isParsedHeader())   assertEquals(retain,b1.isHeaderBytesValid());
  if (b1.isParsedTransactions())   assertEquals(retain,b1.isTransactionBytesValid());
  serDeser(bs,b1,blockBytes,null,null);
  assertEquals(!lazy,b1.isParsedTransactions());
  assertEquals(!lazy,b1.isParsedHeader());
  if (b1.isParsedHeader())   assertEquals(retain,b1.isHeaderBytesValid());
  if (b1.isParsedTransactions())   assertEquals(retain,b1.isTransactionBytesValid());
  bos.reset();
  bsRef.serialize(bRef,bos);
  serDeser(bs,b1,bos.toByteArray(),null,null);
  b1.getTransactions();
  assertTrue(b1.isParsedTransactions());
  if (b1.getTransactions().size() > 0) {
    assertTrue(b1.isParsedTransactions());
    Transaction tx1=b1.getTransactions().get(0);
    if (tx1.isParsed())     assertEquals(retain,tx1.isCached());
 else     assertTrue(tx1.isCached());
    serDeser(bs,b1,bos.toByteArray(),null,null);
  }
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  b1.getDifficultyTarget();
  assertTrue(b1.isParsedHeader());
  assertEquals(lazy,!b1.isParsedTransactions());
  serDeser(bs,b1,bos.toByteArray(),null,null);
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  b1.getDifficultyTarget();
  assertTrue(b1.isParsedHeader());
  assertEquals(lazy,!b1.isParsedTransactions());
  b1.getTransactions();
  assertTrue(b1.isParsedTransactions());
  if (b1.getTransactions().size() > 0) {
    assertTrue(b1.isParsedTransactions());
    Transaction tx1=b1.getTransactions().get(0);
    if (tx1.isParsed())     assertEquals(retain,tx1.isCached());
 else     assertTrue(tx1.isCached());
  }
  serDeser(bs,b1,bos.toByteArray(),null,null);
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  b1.setNonce(23);
  bRef.setNonce(23);
  assertTrue(b1.isParsedHeader());
  assertEquals(lazy,!b1.isParsedTransactions());
  assertFalse(b1.isHeaderBytesValid());
  if (b1.isParsedTransactions())   assertEquals(retain,b1.isTransactionBytesValid());
 else   assertEquals(true,b1.isTransactionBytesValid());
  bos.reset();
  bsRef.serialize(bRef,bos);
  serDeser(bs,b1,bos.toByteArray(),null,null);
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  b1.getTransactions();
  if (b1.getTransactions().size() > 0) {
    Transaction tx1=b1.getTransactions().get(0);
    TransactionInput tin=tx1.getInputs().get(0);
    assertTrue(tx1.isParsed());
    assertTrue(b1.isParsedTransactions());
    assertEquals(!lazy,b1.isParsedHeader());
    assertEquals(!lazy,tin.isParsed());
    assertEquals(tin.isParsed() ? retain : true,tin.isCached());
    bos.reset();
    bsRef.serialize(bRef,bos);
    serDeser(bs,b1,bos.toByteArray(),null,null);
  }
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  b1.getTransactions();
  if (b1.getTransactions().size() > 0) {
    Transaction tx1=b1.getTransactions().get(0);
    if (tx1.getInputs().size() > 0) {
      tx1.addInput(tx1.getInputs().get(0));
      bRef.getTransactions().get(0).addInput(bRef.getTransactions().get(0).getInputs().get(0));
      assertFalse(tx1.isCached());
      assertTrue(tx1.isParsed());
      assertFalse(b1.isTransactionBytesValid());
      assertTrue(b1.isParsedHeader());
      if (tx1.getInputs().size() > 1) {
        boolean parsed=tx1.getInputs().get(1).isParsed();
        assertEquals(parsed ? retain : true,tx1.getInputs().get(1).isCached());
        assertEquals(!lazy,parsed);
      }
      assertFalse(b1.isHeaderBytesValid());
      bos.reset();
      bsRef.serialize(bRef,bos);
      byte[] source=bos.toByteArray();
      serDeser(bs,b1,source,null,null);
    }
    bos.reset();
    bsRef.serialize(bRef,bos);
    serDeser(bs,b1,bos.toByteArray(),null,null);
  }
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  Block b2=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  Block bRef2=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  b1.getTransactions();
  if (b1.getTransactions().size() > 0) {
    Transaction tx1=b1.getTransactions().get(0);
    Transaction tx2=b2.getTransactions().get(0);
    if (tx1.getInputs().size() > 0) {
      TransactionInput fromTx1=tx1.getInputs().get(0);
      tx2.addInput(fromTx1);
      TransactionInput fromTxRef=bRef.getTransactions().get(0).getInputs().get(0);
      bRef2.getTransactions().get(0).addInput(fromTxRef);
      assertFalse(b1.isTransactionBytesValid());
      assertFalse(b2.isTransactionBytesValid());
      bos.reset();
      bsRef.serialize(bRef2,bos);
      byte[] source=bos.toByteArray();
      serDeser(bs,b2,source,null,null);
    }
    bos.reset();
    bsRef.serialize(bRef,bos);
    serDeser(bs,b1,bos.toByteArray(),null,null);
    bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
    bos.reset();
    bsRef.serialize(bRef,bos);
    serDeser(bs,b1,bos.toByteArray(),null,null);
  }
}

Fixed version (ground truth):
public void testBlock(byte[] blockBytes,boolean isChild,boolean lazy,boolean retain) throws Exception {
  BitcoinSerializer bsRef=new BitcoinSerializer(unitTestParams,false,false);
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  BitcoinSerializer bs=new BitcoinSerializer(unitTestParams,lazy,retain);
  Block b1;
  Block bRef;
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  bos.reset();
  bsRef.serialize(bRef,bos);
  assertTrue(Arrays.equals(bos.toByteArray(),blockBytes));
  assertEquals(!lazy,b1.isParsedTransactions());
  assertEquals(!lazy,b1.isParsedHeader());
  if (b1.isParsedHeader())   assertEquals(retain,b1.isHeaderBytesValid());
  if (b1.isParsedTransactions())   assertEquals(retain,b1.isTransactionBytesValid());
  serDeser(bs,b1,blockBytes,null,null);
  assertEquals(!lazy,b1.isParsedTransactions());
  assertEquals(!lazy,b1.isParsedHeader());
  if (b1.isParsedHeader())   assertEquals(retain,b1.isHeaderBytesValid());
  if (b1.isParsedTransactions())   assertEquals(retain,b1.isTransactionBytesValid());
  bos.reset();
  bsRef.serialize(bRef,bos);
  serDeser(bs,b1,bos.toByteArray(),null,null);
  b1.getTransactions();
  assertTrue(b1.isParsedTransactions());
  if (b1.getTransactions().size() > 0) {
    assertTrue(b1.isParsedTransactions());
    Transaction tx1=b1.getTransactions().get(0);
    if (tx1.isParsed())     assertEquals(retain,tx1.isCached());
 else     assertTrue(tx1.isCached());
    serDeser(bs,b1,bos.toByteArray(),null,null);
  }
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  b1.getDifficultyTarget();
  assertTrue(b1.isParsedHeader());
  assertEquals(lazy,!b1.isParsedTransactions());
  serDeser(bs,b1,bos.toByteArray(),null,null);
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  b1.getDifficultyTarget();
  assertTrue(b1.isParsedHeader());
  assertEquals(lazy,!b1.isParsedTransactions());
  b1.getTransactions();
  assertTrue(b1.isParsedTransactions());
  if (b1.getTransactions().size() > 0) {
    assertTrue(b1.isParsedTransactions());
    Transaction tx1=b1.getTransactions().get(0);
    if (tx1.isParsed())     assertEquals(retain,tx1.isCached());
 else     assertTrue(tx1.isCached());
  }
  serDeser(bs,b1,bos.toByteArray(),null,null);
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  b1.setNonce(23);
  bRef.setNonce(23);
  assertTrue(b1.isParsedHeader());
  assertEquals(lazy,!b1.isParsedTransactions());
  assertFalse(b1.isHeaderBytesValid());
  if (b1.isParsedTransactions())   assertEquals(retain,b1.isTransactionBytesValid());
 else   assertEquals(true,b1.isTransactionBytesValid());
  bos.reset();
  bsRef.serialize(bRef,bos);
  serDeser(bs,b1,bos.toByteArray(),null,null);
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  b1.getTransactions();
  if (b1.getTransactions().size() > 0) {
    Transaction tx1=b1.getTransactions().get(0);
    TransactionInput tin=tx1.getInputs().get(0);
    assertTrue(tx1.isParsed());
    assertTrue(b1.isParsedTransactions());
    assertEquals(!lazy,b1.isParsedHeader());
    assertEquals(!lazy,tin.isParsed());
    assertEquals(!tin.isParsed() || retain,tin.isCached());
    bos.reset();
    bsRef.serialize(bRef,bos);
    serDeser(bs,b1,bos.toByteArray(),null,null);
  }
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  b1.getTransactions();
  if (b1.getTransactions().size() > 0) {
    Transaction tx1=b1.getTransactions().get(0);
    if (tx1.getInputs().size() > 0) {
      tx1.addInput(tx1.getInputs().get(0));
      bRef.getTransactions().get(0).addInput(bRef.getTransactions().get(0).getInputs().get(0));
      assertFalse(tx1.isCached());
      assertTrue(tx1.isParsed());
      assertFalse(b1.isTransactionBytesValid());
      assertTrue(b1.isParsedHeader());
      if (tx1.getInputs().size() > 1) {
        boolean parsed=tx1.getInputs().get(1).isParsed();
        assertEquals(!parsed || retain,tx1.getInputs().get(1).isCached());
        assertEquals(!lazy,parsed);
      }
      assertFalse(b1.isHeaderBytesValid());
      bos.reset();
      bsRef.serialize(bRef,bos);
      byte[] source=bos.toByteArray();
      serDeser(bs,b1,source,null,null);
    }
    bos.reset();
    bsRef.serialize(bRef,bos);
    serDeser(bs,b1,bos.toByteArray(),null,null);
  }
  b1=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  Block b2=(Block)bs.deserialize(ByteBuffer.wrap(blockBytes));
  bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  Block bRef2=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
  b1.getTransactions();
  if (b1.getTransactions().size() > 0) {
    Transaction tx1=b1.getTransactions().get(0);
    Transaction tx2=b2.getTransactions().get(0);
    if (tx1.getInputs().size() > 0) {
      TransactionInput fromTx1=tx1.getInputs().get(0);
      tx2.addInput(fromTx1);
      TransactionInput fromTxRef=bRef.getTransactions().get(0).getInputs().get(0);
      bRef2.getTransactions().get(0).addInput(fromTxRef);
      assertFalse(b1.isTransactionBytesValid());
      assertFalse(b2.isTransactionBytesValid());
      bos.reset();
      bsRef.serialize(bRef2,bos);
      byte[] source=bos.toByteArray();
      serDeser(bs,b2,source,null,null);
    }
    bos.reset();
    bsRef.serialize(bRef,bos);
    serDeser(bs,b1,bos.toByteArray(),null,null);
    bRef=(Block)bsRef.deserialize(ByteBuffer.wrap(blockBytes));
    bos.reset();
    bsRef.serialize(bRef,bos);
    serDeser(bs,b1,bos.toByteArray(),null,null);
  }
}