Program: 59953
Project: 59953
Buggy source:
public void writeClassDefinition(ClassDefinition classDef) throws IOException {
  final long start=getCurrentPosition();
  writeTag(BmdTag.CLASS_DEFINITION);
  writeInt32(mapObjectId(classDef.getObjectId()));
  writeInt32(mapObjectId(classDef.getSuperClassObjectId()));
  writeInt32(mapStringId(classDef.getNameStringId()));
  int constantFieldCount=classDef.getConstantFields().size();
  writeInt32(constantFieldCount);
  for (int i=0; i < constantFieldCount; i++) {
    ConstantField field=classDef.getConstantFields().get(i);
    writeInt32(field.getPoolIndex());
    writeInt32(convertType(field.getType()).id);
    writeFieldValue(field.getType(),field.getValue());
  }
  int staticFieldCount=classDef.getStaticFields().size();
  writeInt32(staticFieldCount);
  for (int i=0; i < staticFieldCount; i++) {
    StaticField field=classDef.getStaticFields().get(i);
    writeInt32(mapStringId(field.getFieldNameId()));
    writeInt32(convertType(field.getType()).id);
    writeFieldValue(field.getType(),field.getValue());
  }
  int skippedFieldSize=0;
  List<InstanceField> keptFields=new ArrayList<InstanceField>();
  int instanceFieldCount=classDef.getInstanceFields().size();
  for (int i=0; i < instanceFieldCount; i++) {
    InstanceField field=classDef.getInstanceFields().get(i);
    if (field.getType() != BasicType.OBJECT) {
      skippedFieldSize+=field.getType().size;
    }
 else {
      keptFields.add(field);
    }
  }
  int keptFieldCount=keptFields.size();
  writeInt32(keptFieldCount);
  for (int i=0; i < keptFieldCount; i++) {
    InstanceField field=keptFields.get(i);
    writeInt32(mapStringId(field.getFieldNameId()));
    writeInt32(convertType(field.getType()).id);
  }
  writeInt32(skippedFieldSize);
  if (collectStats) {
    Stats.increment(Stats.Type.CLASS,Stats.Variant.BMD,writer.getCurrentPosition() - start);
  }
}

Fixed version (ground truth):
public void writeClassDefinition(@Nonnull ClassDefinition classDef) throws IOException {
  final long start=getCurrentPosition();
  writeTag(BmdTag.CLASS_DEFINITION);
  writeInt32(mapObjectId(classDef.getObjectId()));
  writeInt32(mapObjectId(classDef.getSuperClassObjectId()));
  writeInt32(mapStringId(classDef.getNameStringId()));
  int constantFieldCount=classDef.getConstantFields().size();
  writeInt32(constantFieldCount);
  for (int i=0; i < constantFieldCount; i++) {
    ConstantField field=classDef.getConstantFields().get(i);
    writeInt32(field.getPoolIndex());
    writeInt32(convertType(field.getType()).id);
    writeFieldValue(field.getType(),field.getValue());
  }
  int staticFieldCount=classDef.getStaticFields().size();
  writeInt32(staticFieldCount);
  for (int i=0; i < staticFieldCount; i++) {
    StaticField field=classDef.getStaticFields().get(i);
    writeInt32(mapStringId(field.getFieldNameId()));
    writeInt32(convertType(field.getType()).id);
    writeFieldValue(field.getType(),field.getValue());
  }
  int skippedFieldSize=0;
  List<InstanceField> keptFields=new ArrayList<InstanceField>();
  int instanceFieldCount=classDef.getInstanceFields().size();
  for (int i=0; i < instanceFieldCount; i++) {
    InstanceField field=classDef.getInstanceFields().get(i);
    if (field.getType() != BasicType.OBJECT) {
      skippedFieldSize+=field.getType().size;
    }
 else {
      keptFields.add(field);
    }
  }
  int keptFieldCount=keptFields.size();
  writeInt32(keptFieldCount);
  for (int i=0; i < keptFieldCount; i++) {
    InstanceField field=keptFields.get(i);
    writeInt32(mapStringId(field.getFieldNameId()));
    writeInt32(convertType(field.getType()).id);
  }
  writeInt32(skippedFieldSize);
  if (collectStats) {
    Stats.increment(Stats.Type.CLASS,Stats.Variant.BMD,writer.getCurrentPosition() - start);
  }
}