Program: 80198
Project: 80198
Buggy source:
/** 
 * Build a new instance of   {@link DBObject} from the persistence classinstance in parameter. Limit the  {@link DBObject} to the fields that aredirty and not null, that is the fields that will need to be updated in the store. <p/> This implementation mainly differs from the {@link MongoStore#newInstance(Persistent)} one from two points:<ol> <li>the restriction to fields that are dirty and then need an update</li> <li>the qualification of field names as fully qualified names</li> </ol>
 * @param persistent a persistence class instance which content is to be serialized as a  {@link DBObject} for use as parameter of a $set operator
 * @return a {@link DBObject} which content corresponds to the fields thathave to be updated... and formated to be passed in parameter of a $set operator
 */
private BasicDBObject newUpdateSetInstance(T persistent){
  BasicDBObject result=new BasicDBObject();
  for (  Field f : persistent.getSchema().getFields()) {
    if (persistent.isReadable(f.pos()) && persistent.isDirty(f.pos()) && (persistent.get(f.pos()) != null)) {
      String docf=mapping.getDocumentField(f.name());
      DocumentFieldType storeType=mapping.getDocumentFieldType(docf);
      Object value=persistent.get(f.pos());
switch (f.schema().getType()) {
case MAP:
        if (storeType != DocumentFieldType.DOCUMENT) {
          throw new IllegalStateException("String_Node_Str" + f.name() + "String_Node_Str");
        }
      result.put(docf,toMongoMap((Map<Utf8,?>)value,f.schema().getValueType().getType()));
    break;
case ARRAY:
  if (storeType != DocumentFieldType.LIST) {
    throw new IllegalStateException("String_Node_Str" + f.name() + "String_Node_Str");
  }
result.put(docf,toMongoList((GenericArray<?>)value,f.schema().getElementType().getType()));
break;
case BYTES:
if (value != null) result.put(docf,((ByteBuffer)value).array());
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" + f.name() + "String_Node_Str");
}
result.put(docf,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" + f.name() + "String_Node_Str"+ value+ "String_Node_Str");
}
result.put(docf,calendar.getTime());
}
}
 else {
if (value != null) {
result.put(docf,value.toString());
}
}
break;
case ENUM:
if (value != null) result.put(docf,value.toString());
break;
case RECORD:
if (value == null) break;
BasicDBObject record=new BasicDBObject();
for (Field member : f.schema().getFields()) {
Object recValue=((PersistentBase)value).get(member.pos());
switch (member.schema().getType()) {
case MAP:
record.put(member.name(),toMongoMap((Map<Utf8,?>)recValue,member.schema().getElementType().getType()));
case ARRAY:
record.put(member.name(),toMongoList((GenericArray<?>)recValue,member.schema().getElementType().getType()));
break;
case STRING:
case ENUM:
if (recValue != null) record.put(member.name(),recValue.toString());
break;
case BYTES:
if (recValue != null) record.put(member.name(),((ByteBuffer)recValue).array());
break;
case RECORD:
throw new IllegalStateException("String_Node_Str" + "String_Node_Str");
default :
record.put(member.name(),recValue);
break;
}
}
result.put(docf,record);
break;
default :
result.put(docf,value);
break;
}
}
}
return result;
}

Fixed version (ground truth):
/** 
 * Build a new instance of   {@link DBObject} from the persistence classinstance in parameter. Limit the  {@link DBObject} to the fields that aredirty and not null, that is the fields that will need to be updated in the store. <p/> This implementation mainly differs from the {@link MongoStore#newInstance(Persistent)} one from two points:<ol> <li>the restriction to fields that are dirty and then need an update</li> <li>the qualification of field names as fully qualified names</li> </ol>
 * @param persistent a persistence class instance which content is to be serialized as a  {@link DBObject} for use as parameter of a $set operator
 * @return a {@link DBObject} which content corresponds to the fields thathave to be updated... and formated to be passed in parameter of a $set operator
 */
private BasicDBObject newUpdateSetInstance(T persistent){
  BasicDBObject result=new BasicDBObject();
  for (  Field f : persistent.getSchema().getFields()) {
    if (persistent.isReadable(f.pos()) && persistent.isDirty(f.pos()) && (persistent.get(f.pos()) != null)) {
      String docf=mapping.getDocumentField(f.name());
      DocumentFieldType storeType=mapping.getDocumentFieldType(docf);
      Object value=persistent.get(f.pos());
switch (f.schema().getType()) {
case MAP:
        if (storeType != DocumentFieldType.DOCUMENT) {
          throw new IllegalStateException("String_Node_Str" + f.name() + "String_Node_Str");
        }
      result.put(docf,toMongoMap((Map<Utf8,?>)value,f.schema().getValueType().getType()));
    break;
case ARRAY:
  if (storeType != DocumentFieldType.LIST) {
    throw new IllegalStateException("String_Node_Str" + f.name() + "String_Node_Str");
  }
result.put(docf,toMongoList((GenericArray<?>)value,f.schema().getElementType().getType()));
break;
case BYTES:
if (value != null) result.put(docf,((ByteBuffer)value).array());
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" + f.name() + "String_Node_Str");
}
result.put(docf,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" + f.name() + "String_Node_Str"+ value+ "String_Node_Str");
}
result.put(docf,calendar.getTime());
}
}
 else {
if (value != null) {
result.put(docf,value.toString());
}
}
break;
case ENUM:
if (value != null) result.put(docf,value.toString());
break;
case RECORD:
if (value == null) break;
BasicDBObject record=new BasicDBObject();
for (Field member : f.schema().getFields()) {
Object recValue=((PersistentBase)value).get(member.pos());
switch (member.schema().getType()) {
case MAP:
record.put(member.name(),toMongoMap((Map<Utf8,?>)recValue,member.schema().getValueType().getType()));
break;
case ARRAY:
record.put(member.name(),toMongoList((GenericArray<?>)recValue,member.schema().getElementType().getType()));
break;
case STRING:
case ENUM:
if (recValue != null) record.put(member.name(),recValue.toString());
break;
case BYTES:
if (recValue != null) record.put(member.name(),((ByteBuffer)recValue).array());
break;
case RECORD:
throw new IllegalStateException("String_Node_Str" + "String_Node_Str");
default :
record.put(member.name(),recValue);
break;
}
}
result.put(docf,record);
break;
default :
result.put(docf,value);
break;
}
}
}
return result;
}