Program: 113135
Project: 113135
Buggy source:
@Override public byte[] toBinary(){
  final byte[] coverageNameBytes=StringUtils.stringToBinary(coverageName);
  final byte[] sampleModelBinary=getSampleModelBinary(sampleModel);
  final byte[] colorModelBinary=getColorModelBinary(colorModel);
  int metadataBinaryLength=4;
  final List<byte[]> entryBinaries=new ArrayList<byte[]>();
  for (  final Entry<String,String> e : metadata.entrySet()) {
    final byte[] keyBytes=StringUtils.stringToBinary(e.getKey());
    final byte[] valueBytes=StringUtils.stringToBinary(e.getValue());
    final int entryBinaryLength=4 + valueBytes.length + keyBytes.length;
    final ByteBuffer buf=ByteBuffer.allocate(entryBinaryLength);
    buf.putInt(keyBytes.length);
    buf.put(keyBytes);
    buf.put(valueBytes);
    entryBinaries.add(buf.array());
    metadataBinaryLength+=(entryBinaryLength + 4);
  }
  byte[] histogramConfigBinary;
  if (histogramConfig != null) {
    histogramConfigBinary=PersistenceUtils.toBinary(histogramConfig);
  }
 else {
    histogramConfigBinary=new byte[]{};
  }
  final byte[] noDataBinary=getNoDataBinary(noDataValuesPerBand);
  final byte[] backgroundBinary;
  if (backgroundValuesPerBand != null) {
    final int totalBytes=(backgroundValuesPerBand.length * 8);
    final ByteBuffer backgroundBuf=ByteBuffer.allocate(totalBytes);
    for (    final double backgroundValue : backgroundValuesPerBand) {
      backgroundBuf.putDouble(backgroundValue);
    }
    backgroundBinary=backgroundBuf.array();
  }
 else {
    backgroundBinary=new byte[]{};
  }
  byte[] mergeStrategyBinary;
  if (mergeStrategy != null) {
    mergeStrategyBinary=PersistenceUtils.toBinary(mergeStrategy);
  }
 else {
    mergeStrategyBinary=new byte[]{};
  }
  final ByteBuffer buf=ByteBuffer.allocate(coverageNameBytes.length + sampleModelBinary.length + colorModelBinary.length+ metadataBinaryLength+ histogramConfigBinary.length+ noDataBinary.length+ backgroundBinary.length+ 29);
  buf.putInt(tileSize);
  buf.putInt(coverageNameBytes.length);
  buf.put(coverageNameBytes);
  buf.putInt(sampleModelBinary.length);
  buf.put(sampleModelBinary);
  buf.putInt(colorModelBinary.length);
  buf.put(colorModelBinary);
  buf.putInt(entryBinaries.size());
  for (  final byte[] entryBinary : entryBinaries) {
    buf.putInt(entryBinary.length);
    buf.put(entryBinary);
  }
  buf.putInt(histogramConfigBinary.length);
  buf.put(histogramConfigBinary);
  buf.putInt(noDataBinary.length);
  buf.put(noDataBinary);
  buf.putInt(backgroundBinary.length);
  buf.put(backgroundBinary);
  buf.putInt(mergeStrategyBinary.length);
  buf.put(mergeStrategyBinary);
  buf.put(buildPyramid ? (byte)1 : (byte)0);
  return buf.array();
}

Fixed version (ground truth):
@Override public byte[] toBinary(){
  final byte[] coverageNameBytes=StringUtils.stringToBinary(coverageName);
  final byte[] sampleModelBinary=getSampleModelBinary(sampleModel);
  final byte[] colorModelBinary=getColorModelBinary(colorModel);
  int metadataBinaryLength=4;
  final List<byte[]> entryBinaries=new ArrayList<byte[]>();
  for (  final Entry<String,String> e : metadata.entrySet()) {
    final byte[] keyBytes=StringUtils.stringToBinary(e.getKey());
    final byte[] valueBytes=StringUtils.stringToBinary(e.getValue());
    final int entryBinaryLength=4 + valueBytes.length + keyBytes.length;
    final ByteBuffer buf=ByteBuffer.allocate(entryBinaryLength);
    buf.putInt(keyBytes.length);
    buf.put(keyBytes);
    buf.put(valueBytes);
    entryBinaries.add(buf.array());
    metadataBinaryLength+=(entryBinaryLength + 4);
  }
  byte[] histogramConfigBinary;
  if (histogramConfig != null) {
    histogramConfigBinary=PersistenceUtils.toBinary(histogramConfig);
  }
 else {
    histogramConfigBinary=new byte[]{};
  }
  final byte[] noDataBinary=getNoDataBinary(noDataValuesPerBand);
  final byte[] backgroundBinary;
  if (backgroundValuesPerBand != null) {
    final int totalBytes=(backgroundValuesPerBand.length * 8);
    final ByteBuffer backgroundBuf=ByteBuffer.allocate(totalBytes);
    for (    final double backgroundValue : backgroundValuesPerBand) {
      backgroundBuf.putDouble(backgroundValue);
    }
    backgroundBinary=backgroundBuf.array();
  }
 else {
    backgroundBinary=new byte[]{};
  }
  byte[] mergeStrategyBinary;
  if (mergeStrategy != null) {
    mergeStrategyBinary=PersistenceUtils.toBinary(mergeStrategy);
  }
 else {
    mergeStrategyBinary=new byte[]{};
  }
  final ByteBuffer buf=ByteBuffer.allocate(coverageNameBytes.length + sampleModelBinary.length + colorModelBinary.length+ metadataBinaryLength+ histogramConfigBinary.length+ noDataBinary.length+ backgroundBinary.length+ mergeStrategyBinary.length+ 33);
  buf.putInt(tileSize);
  buf.putInt(coverageNameBytes.length);
  buf.put(coverageNameBytes);
  buf.putInt(sampleModelBinary.length);
  buf.put(sampleModelBinary);
  buf.putInt(colorModelBinary.length);
  buf.put(colorModelBinary);
  buf.putInt(entryBinaries.size());
  for (  final byte[] entryBinary : entryBinaries) {
    buf.putInt(entryBinary.length);
    buf.put(entryBinary);
  }
  buf.putInt(histogramConfigBinary.length);
  buf.put(histogramConfigBinary);
  buf.putInt(noDataBinary.length);
  buf.put(noDataBinary);
  buf.putInt(backgroundBinary.length);
  buf.put(backgroundBinary);
  buf.putInt(mergeStrategyBinary.length);
  buf.put(mergeStrategyBinary);
  buf.put(buildPyramid ? (byte)1 : (byte)0);
  return buf.array();
}