Program: 80191
Project: 80191
Buggy source:
private Object toDBObject(Schema fieldSchema,Type fieldType,DocumentFieldType storeType,Object value){
  Object result=null;
switch (fieldType) {
case MAP:
    if (storeType != null && storeType != DocumentFieldType.DOCUMENT) {
      throw new IllegalStateException("String_Node_Str" + fieldSchema.getType() + "String_Node_Str");
    }
  Schema valueSchema=fieldSchema.getValueType();
result=toMongoMap((Map<Utf8,?>)value,valueSchema.getType());
break;
case ARRAY:
if (storeType != null && storeType != DocumentFieldType.LIST) {
throw new IllegalStateException("String_Node_Str" + fieldSchema.getType() + "String_Node_Str");
}
Schema elementSchema=fieldSchema.getElementType();
result=toMongoList((GenericArray<?>)value,elementSchema.getType());
break;
case BYTES:
if (value != null) {
result=((ByteBuffer)value).array();
}
break;
case INT:
case LONG:
case FLOAT:
case DOUBLE:
case BOOLEAN:
result=value;
break;
case STRING:
if (storeType == DocumentFieldType.OBJECTID) {
if (value != null) {
ObjectId id;
try {
id=new ObjectId(value.toString());
}
 catch (IllegalArgumentException e1) {
throw new IllegalStateException("String_Node_Str" + fieldSchema.getType() + "String_Node_Str");
}
result=id;
}
}
 else if (storeType == DocumentFieldType.DATE) {
if (value != null) {
Calendar calendar=null;
try {
calendar=DatatypeConverter.parseDateTime(value.toString());
}
 catch (IllegalArgumentException e1) {
try {
calendar=DatatypeConverter.parseDate(value.toString());
}
 catch (IllegalArgumentException e2) {
}
}
if (calendar == null) {
throw new IllegalStateException("String_Node_Str" + fieldSchema.getType() + "String_Node_Str"+ value+ "String_Node_Str");
}
result=calendar.getTime();
}
}
 else {
if (value != null) {
result=value.toString();
}
}
break;
case ENUM:
if (value != null) result=value.toString();
break;
case RECORD:
if (value == null) break;
BasicDBObject record=new BasicDBObject();
for (Field member : fieldSchema.getFields()) {
Object innerValue=((PersistentBase)value).get(member.pos());
String innerDoc=mapping.getDocumentField(member.name());
Type innerType=member.schema().getType();
DocumentFieldType innerStoreType=mapping.getDocumentFieldType(innerDoc);
record.put(member.name(),toDBObject(member.schema(),innerType,innerStoreType,innerValue));
}
result=record;
break;
case UNION:
Type type0=fieldSchema.getTypes().get(0).getType();
Type type1=fieldSchema.getTypes().get(1).getType();
if (!type0.equals(type1) && (type0.equals(Schema.Type.NULL) || type1.equals(Schema.Type.NULL))) {
Schema innerSchema=fieldSchema.getTypes().get(1);
DocumentFieldType innerStoreType=mapping.getDocumentFieldType(innerSchema.getName());
result=toDBObject(innerSchema,type1,innerStoreType,value);
}
break;
case FIXED:
result=value;
break;
default :
LOG.error("String_Node_Str" + fieldSchema.getType());
break;
}
return result;
}

Fixed version (ground truth):
private Object toDBObject(Schema fieldSchema,Type fieldType,DocumentFieldType storeType,Object value){
  Object result=null;
switch (fieldType) {
case MAP:
    if (storeType != null && storeType != DocumentFieldType.DOCUMENT) {
      throw new IllegalStateException("String_Node_Str" + fieldSchema.getType() + "String_Node_Str");
    }
  Schema valueSchema=fieldSchema.getValueType();
result=toMongoMap((Map<Utf8,?>)value,valueSchema.getType());
break;
case ARRAY:
if (storeType != null && storeType != DocumentFieldType.LIST) {
throw new IllegalStateException("String_Node_Str" + fieldSchema.getType() + "String_Node_Str");
}
Schema elementSchema=fieldSchema.getElementType();
result=toMongoList((GenericArray<?>)value,elementSchema.getType());
break;
case BYTES:
if (value != null) {
result=((ByteBuffer)value).array();
}
break;
case INT:
case LONG:
case FLOAT:
case DOUBLE:
case BOOLEAN:
result=value;
break;
case STRING:
if (storeType == DocumentFieldType.OBJECTID) {
if (value != null) {
ObjectId id;
try {
id=new ObjectId(value.toString());
}
 catch (IllegalArgumentException e1) {
throw new IllegalStateException("String_Node_Str" + fieldSchema.getType() + "String_Node_Str");
}
result=id;
}
}
 else if (storeType == DocumentFieldType.DATE) {
if (value != null) {
Calendar calendar=null;
try {
calendar=DatatypeConverter.parseDateTime(value.toString());
}
 catch (IllegalArgumentException e1) {
try {
calendar=DatatypeConverter.parseDate(value.toString());
}
 catch (IllegalArgumentException e2) {
}
}
if (calendar == null) {
throw new IllegalStateException("String_Node_Str" + fieldSchema.getType() + "String_Node_Str"+ value+ "String_Node_Str");
}
result=calendar.getTime();
}
}
 else {
if (value != null) {
result=value.toString();
}
}
break;
case ENUM:
if (value != null) result=value.toString();
break;
case RECORD:
if (value == null) break;
BasicDBObject record=new BasicDBObject();
for (Field member : fieldSchema.getFields()) {
Object innerValue=((PersistentBase)value).get(member.pos());
String innerDoc=mapping.getDocumentField(member.name());
Type innerType=member.schema().getType();
DocumentFieldType innerStoreType=mapping.getDocumentFieldType(innerDoc);
LOG.debug("String_Node_Str",new Object[]{member.name(),member.schema().getType(),innerStoreType});
record.put(member.name(),toDBObject(member.schema(),innerType,innerStoreType,innerValue));
}
result=record;
break;
case UNION:
Type type0=fieldSchema.getTypes().get(0).getType();
Type type1=fieldSchema.getTypes().get(1).getType();
if (!type0.equals(type1) && (type0.equals(Schema.Type.NULL) || type1.equals(Schema.Type.NULL))) {
Schema innerSchema=fieldSchema.getTypes().get(1);
DocumentFieldType innerStoreType=mapping.getDocumentFieldType(innerSchema.getName());
LOG.debug("String_Node_Str",new Object[]{innerSchema.getType(),type1,innerStoreType});
result=toDBObject(innerSchema,type1,innerStoreType,value);
}
break;
case FIXED:
result=value;
break;
default :
LOG.error("String_Node_Str" + fieldSchema.getType());
break;
}
return result;
}