Program: 55664
Project: 55664
Buggy source:
/** 
 * Updates the binary representation of the data, such that it reflects the state of the currently stored fields. If the binary representation is already up to date, nothing happens. Otherwise, this function triggers the modified fields to serialize themselves into the records buffer and afterwards updates the offset table.
 */
public void updateBinaryRepresenation(){
  final int firstModified=this.firstModifiedPos;
  if (firstModified == Integer.MAX_VALUE)   return;
  final InternalDeSerializer serializer=this.serializer;
  final int[] offsets=this.offsets;
  final int numFields=this.numFields;
  if (numFields > 0) {
    int offset=0;
    if (firstModified > 0) {
      for (int i=firstModified - 1; i >= 0; i--) {
        if (this.offsets[i] != NULL_INDICATOR_OFFSET) {
          offset=this.offsets[i] + this.lengths[i];
          break;
        }
      }
    }
    serializer.memory=this.switchBuffer != null ? this.switchBuffer : new byte[numFields * 8];
    serializer.position=offset;
    if (offset > 0) {
      System.arraycopy(this.binaryData,0,serializer.memory,0,offset);
    }
    try {
      for (int i=firstModified; i < numFields; i++) {
        final int co=offsets[i];
        if (co == NULL_INDICATOR_OFFSET)         continue;
        offsets[i]=offset;
        if (co == MODIFIED_INDICATOR_OFFSET)         this.writeFields[i].write(serializer);
 else         serializer.write(this.binaryData,co,this.lengths[i]);
        this.lengths[i]=serializer.position - offset;
        offset=serializer.position;
      }
    }
 catch (    Exception e) {
      throw new RuntimeException("String_Node_Str" + e.getMessage(),e);
    }
    this.switchBuffer=this.binaryData;
    this.binaryData=serializer.memory;
  }
  try {
    int slp=serializer.position;
    if (numFields <= 8) {
      int mask=0;
      for (int i=numFields - 1; i > 0; i--) {
        if (offsets[i] != NULL_INDICATOR_OFFSET) {
          slp=serializer.position;
          serializer.writeValLenIntBackwards(offsets[i]);
          mask|=0x1;
        }
        mask<<=1;
      }
      if (offsets[0] != NULL_INDICATOR_OFFSET) {
        mask|=0x1;
      }
 else {
        serializer.position=slp;
      }
      serializer.writeByte(mask);
    }
 else {
      for (int i=numFields - 1; i > 0; i--) {
        if (offsets[i] != NULL_INDICATOR_OFFSET) {
          slp=serializer.position;
          serializer.writeValLenIntBackwards(offsets[i]);
        }
      }
      if (offsets[0] == NULL_INDICATOR_OFFSET) {
        serializer.position=slp;
      }
      int col=numFields - 1;
      int mask=0;
      for (int i=numFields & 0x7; i > 0; i--, col--) {
        mask<<=1;
        mask|=(offsets[col] != NULL_INDICATOR_OFFSET) ? 0x1 : 0x0;
      }
      serializer.writeByte(mask);
      for (int i=numFields >>> 3; i > 0; i--) {
        mask=0;
        for (int k=0; k < 8; k++, col--) {
          mask<<=1;
          mask|=(offsets[col] != NULL_INDICATOR_OFFSET) ? 0x1 : 0x0;
        }
        serializer.writeByte(mask);
      }
    }
    serializer.writeValLenIntBackwards(numFields);
  }
 catch (  Exception e) {
    throw new RuntimeException("String_Node_Str" + e.getMessage(),e);
  }
  this.binaryData=serializer.memory;
  this.binaryLen=serializer.position;
  this.firstModifiedPos=Integer.MAX_VALUE;
}

Fixed version (ground truth):
/** 
 * Updates the binary representation of the data, such that it reflects the state of the currently stored fields. If the binary representation is already up to date, nothing happens. Otherwise, this function triggers the modified fields to serialize themselves into the records buffer and afterwards updates the offset table.
 */
public void updateBinaryRepresenation(){
  final int firstModified=this.firstModifiedPos < 0 ? 0 : this.firstModifiedPos;
  if (firstModified == Integer.MAX_VALUE)   return;
  final InternalDeSerializer serializer=this.serializer;
  final int[] offsets=this.offsets;
  final int numFields=this.numFields;
  if (numFields > 0) {
    int offset=0;
    if (firstModified > 0) {
      for (int i=firstModified - 1; i >= 0; i--) {
        if (this.offsets[i] != NULL_INDICATOR_OFFSET) {
          offset=this.offsets[i] + this.lengths[i];
          break;
        }
      }
    }
    serializer.memory=this.switchBuffer != null ? this.switchBuffer : new byte[numFields * 8];
    serializer.position=offset;
    if (offset > 0) {
      System.arraycopy(this.binaryData,0,serializer.memory,0,offset);
    }
    try {
      for (int i=firstModified; i < numFields; i++) {
        final int co=offsets[i];
        if (co == NULL_INDICATOR_OFFSET)         continue;
        offsets[i]=offset;
        if (co == MODIFIED_INDICATOR_OFFSET)         this.writeFields[i].write(serializer);
 else         serializer.write(this.binaryData,co,this.lengths[i]);
        this.lengths[i]=serializer.position - offset;
        offset=serializer.position;
      }
    }
 catch (    Exception e) {
      throw new RuntimeException("String_Node_Str" + e.getMessage(),e);
    }
    this.switchBuffer=this.binaryData;
    this.binaryData=serializer.memory;
  }
  try {
    int slp=serializer.position;
    if (numFields <= 8) {
      int mask=0;
      for (int i=numFields - 1; i > 0; i--) {
        if (offsets[i] != NULL_INDICATOR_OFFSET) {
          slp=serializer.position;
          serializer.writeValLenIntBackwards(offsets[i]);
          mask|=0x1;
        }
        mask<<=1;
      }
      if (offsets[0] != NULL_INDICATOR_OFFSET) {
        mask|=0x1;
      }
 else {
        serializer.position=slp;
      }
      serializer.writeByte(mask);
    }
 else {
      for (int i=numFields - 1; i > 0; i--) {
        if (offsets[i] != NULL_INDICATOR_OFFSET) {
          slp=serializer.position;
          serializer.writeValLenIntBackwards(offsets[i]);
        }
      }
      if (offsets[0] == NULL_INDICATOR_OFFSET) {
        serializer.position=slp;
      }
      int col=numFields - 1;
      int mask=0;
      for (int i=numFields & 0x7; i > 0; i--, col--) {
        mask<<=1;
        mask|=(offsets[col] != NULL_INDICATOR_OFFSET) ? 0x1 : 0x0;
      }
      serializer.writeByte(mask);
      for (int i=numFields >>> 3; i > 0; i--) {
        mask=0;
        for (int k=0; k < 8; k++, col--) {
          mask<<=1;
          mask|=(offsets[col] != NULL_INDICATOR_OFFSET) ? 0x1 : 0x0;
        }
        serializer.writeByte(mask);
      }
    }
    serializer.writeValLenIntBackwards(numFields);
  }
 catch (  Exception e) {
    throw new RuntimeException("String_Node_Str" + e.getMessage(),e);
  }
  this.binaryData=serializer.memory;
  this.binaryLen=serializer.position;
  this.firstModifiedPos=Integer.MAX_VALUE;
}