Program: 175965
Project: 175965
Buggy source:
/** 
 * Creates MongoDB Query object from filterClauseQueue.
 * @param m the m
 * @param filterClauseQueue the filter clause queue
 * @param columns
 * @return the basic db object
 */
public BasicDBObject createSubMongoQuery(EntityMetadata m,Queue filterClauseQueue){
  BasicDBObject query=new BasicDBObject();
  BasicDBObject compositeColumns=new BasicDBObject();
  MetamodelImpl metaModel=(MetamodelImpl)kunderaMetadata.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
  AbstractManagedType managedType=(AbstractManagedType)metaModel.entity(m.getEntityClazz());
  for (  Object object : filterClauseQueue) {
    boolean isCompositeColumn=false;
    boolean isSubCondition=false;
    if (object instanceof FilterClause) {
      FilterClause filter=(FilterClause)object;
      String property=filter.getProperty();
      String condition=filter.getCondition();
      Object value=filter.getValue().get(0);
      Field f=null;
      if (managedType.hasLobAttribute()) {
        EntityType entity=metaModel.entity(m.getEntityClazz());
        String fieldName=m.getFieldName(property);
        f=(Field)entity.getAttribute(fieldName).getJavaMember();
        if (value.getClass().isAssignableFrom(String.class) && f != null && !f.getType().equals(value.getClass())) {
          value=PropertyAccessorFactory.getPropertyAccessor(f).fromString(f.getType().getClass(),value.toString());
        }
        value=MongoDBUtils.populateValue(value,value.getClass());
        property="String_Node_Str" + property;
      }
 else {
        if (((AbstractAttribute)m.getIdAttribute()).getJPAColumnName().equalsIgnoreCase(property)) {
          property="String_Node_Str";
          f=(Field)m.getIdAttribute().getJavaMember();
          if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()) && value.getClass().isAssignableFrom(f.getType())) {
            EmbeddableType compoundKey=metaModel.embeddable(m.getIdAttribute().getBindableJavaType());
            compositeColumns=MongoDBUtils.getCompoundKeyColumns(m,value,compoundKey);
            isCompositeColumn=true;
            continue;
          }
        }
 else         if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()) && StringUtils.contains(property,'.')) {
          property=property.substring(property.indexOf("String_Node_Str") + 1);
          isCompositeColumn=true;
        }
 else         if (StringUtils.contains(property,'.')) {
          EntityType entity=metaModel.entity(m.getEntityClazz());
          StringTokenizer tokenizer=new StringTokenizer(property,"String_Node_Str");
          String embeddedAttributeAsStr=tokenizer.nextToken();
          String embeddableAttributeAsStr=tokenizer.nextToken();
          Attribute embeddedAttribute=entity.getAttribute(embeddedAttributeAsStr);
          EmbeddableType embeddableEntity=metaModel.embeddable(((AbstractAttribute)embeddedAttribute).getBindableJavaType());
          f=(Field)embeddableEntity.getAttribute(embeddableAttributeAsStr).getJavaMember();
          property=((AbstractAttribute)embeddedAttribute).getJPAColumnName() + "String_Node_Str" + ((AbstractAttribute)embeddableEntity.getAttribute(embeddableAttributeAsStr)).getJPAColumnName();
        }
 else {
          EntityType entity=metaModel.entity(m.getEntityClazz());
          String discriminatorColumn=((AbstractManagedType)entity).getDiscriminatorColumn();
          if (!property.equals(discriminatorColumn)) {
            String fieldName=m.getFieldName(property);
            f=(Field)entity.getAttribute(fieldName).getJavaMember();
          }
        }
        if (value.getClass().isAssignableFrom(String.class) && f != null && !f.getType().equals(value.getClass())) {
          value=PropertyAccessorFactory.getPropertyAccessor(f).fromString(f.getType().getClass(),value.toString());
        }
        value=MongoDBUtils.populateValue(value,value.getClass());
      }
      if (f != null && f.getType().equals(Point.class)) {
        GeospatialQuery geospatialQueryimpl=GeospatialQueryFactory.getGeospatialQueryImplementor(condition,value);
        query=(BasicDBObject)geospatialQueryimpl.createGeospatialQuery(property,value,query);
      }
 else {
        if (isCompositeColumn) {
          property=new StringBuffer("String_Node_Str").append(property).toString();
        }
        if (condition.equals("String_Node_Str")) {
          query.append(property,value);
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",createLikeRegex((String)value)));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",createLikeRegex((String)value)));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",value));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",value));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",value));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",value));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",value));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",value));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",value));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",value));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",filter.getValue()));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",filter.getValue()));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",filter.getValue()));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",filter.getValue()));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",value));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",value));
          }
        }
      }
    }
  }
  if (!compositeColumns.isEmpty()) {
    query.append("String_Node_Str",compositeColumns);
  }
  return query;
}

Fixed version (ground truth):
/** 
 * Creates MongoDB Query object from filterClauseQueue.
 * @param m the m
 * @param filterClauseQueue the filter clause queue
 * @param columns
 * @return the basic db object
 */
public BasicDBObject createSubMongoQuery(EntityMetadata m,Queue filterClauseQueue){
  BasicDBObject query=new BasicDBObject();
  BasicDBObject compositeColumns=new BasicDBObject();
  MetamodelImpl metaModel=(MetamodelImpl)kunderaMetadata.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
  AbstractManagedType managedType=(AbstractManagedType)metaModel.entity(m.getEntityClazz());
  for (  Object object : filterClauseQueue) {
    boolean isCompositeColumn=false;
    boolean isSubCondition=false;
    if (object instanceof FilterClause) {
      FilterClause filter=(FilterClause)object;
      String property=filter.getProperty();
      String condition=filter.getCondition();
      Object value=filter.getValue().get(0);
      Field f=null;
      if (managedType.hasLobAttribute()) {
        EntityType entity=metaModel.entity(m.getEntityClazz());
        String fieldName=m.getFieldName(property);
        f=(Field)entity.getAttribute(fieldName).getJavaMember();
        if (value.getClass().isAssignableFrom(String.class) && f != null && !f.getType().equals(value.getClass())) {
          value=PropertyAccessorFactory.getPropertyAccessor(f).fromString(f.getType().getClass(),value.toString());
        }
        value=MongoDBUtils.populateValue(value,value.getClass());
        property="String_Node_Str" + property;
      }
 else {
        if (((AbstractAttribute)m.getIdAttribute()).getJPAColumnName().equalsIgnoreCase(property)) {
          property="String_Node_Str";
          f=(Field)m.getIdAttribute().getJavaMember();
          if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()) && value.getClass().isAssignableFrom(f.getType())) {
            EmbeddableType compoundKey=metaModel.embeddable(m.getIdAttribute().getBindableJavaType());
            compositeColumns=MongoDBUtils.getCompoundKeyColumns(m,value,compoundKey);
            isCompositeColumn=true;
            continue;
          }
        }
 else         if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()) && StringUtils.contains(property,'.')) {
          property=property.substring(property.indexOf("String_Node_Str") + 1);
          isCompositeColumn=true;
        }
 else         if (StringUtils.contains(property,'.')) {
          EntityType entity=metaModel.entity(m.getEntityClazz());
          StringTokenizer tokenizer=new StringTokenizer(property,"String_Node_Str");
          String embeddedAttributeAsStr=tokenizer.nextToken();
          String embeddableAttributeAsStr=tokenizer.nextToken();
          Attribute embeddedAttribute=entity.getAttribute(embeddedAttributeAsStr);
          EmbeddableType embeddableEntity=metaModel.embeddable(((AbstractAttribute)embeddedAttribute).getBindableJavaType());
          f=(Field)embeddableEntity.getAttribute(embeddableAttributeAsStr).getJavaMember();
          property=((AbstractAttribute)embeddedAttribute).getJPAColumnName() + "String_Node_Str" + ((AbstractAttribute)embeddableEntity.getAttribute(embeddableAttributeAsStr)).getJPAColumnName();
        }
 else {
          EntityType entity=metaModel.entity(m.getEntityClazz());
          String discriminatorColumn=((AbstractManagedType)entity).getDiscriminatorColumn();
          if (!property.equals(discriminatorColumn)) {
            String fieldName=m.getFieldName(property);
            f=(Field)entity.getAttribute(fieldName).getJavaMember();
          }
        }
        if (value.getClass().isAssignableFrom(String.class) && f != null && !f.getType().equals(value.getClass())) {
          value=PropertyAccessorFactory.getPropertyAccessor(f).fromString(f.getType().getClass(),value.toString());
        }
        value=MongoDBUtils.populateValue(value,value.getClass());
      }
      if (f != null && f.getType().equals(Point.class)) {
        GeospatialQuery geospatialQueryimpl=GeospatialQueryFactory.getGeospatialQueryImplementor(condition,value);
        query=(BasicDBObject)geospatialQueryimpl.createGeospatialQuery(property,value,query);
      }
 else {
        if (isCompositeColumn) {
          EmbeddableType embeddableType=metaModel.embeddable(m.getIdAttribute().getBindableJavaType());
          AbstractAttribute attribute=(AbstractAttribute)embeddableType.getAttribute(property);
          property=new StringBuffer("String_Node_Str").append(attribute.getJPAColumnName()).toString();
        }
        if (condition.equals("String_Node_Str")) {
          query.append(property,value);
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",createLikeRegex((String)value)));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",createLikeRegex((String)value)));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",value));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",value));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",value));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",value));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",value));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",value));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",value));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",value));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",filter.getValue()));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",filter.getValue()));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",filter.getValue()));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",filter.getValue()));
          }
        }
 else         if (condition.equalsIgnoreCase("String_Node_Str")) {
          if (query.containsField(property)) {
            query.get(property);
            query.put(property,((BasicDBObject)query.get(property)).append("String_Node_Str",value));
          }
 else {
            query.append(property,new BasicDBObject("String_Node_Str",value));
          }
        }
      }
    }
  }
  if (!compositeColumns.isEmpty()) {
    query.append("String_Node_Str",compositeColumns);
  }
  return query;
}