Program: 63742
Project: 63742
Buggy source:
/** 
 * Generates NamedNativeQueryMetadata for CRUD operations (create, findAll, findByPk, update and delete) for a given Entity if required, i.e. generateCRUDOps is true.
 */
@SuppressWarnings("String_Node_Str") protected void generateCRUDMetadata(EntityAccessor entity){
  if (generateCRUDOps) {
    if (entity.getNamedNativeQueries() == null) {
      entity.setNamedNativeQueries(new ArrayList<NamedNativeQueryMetadata>());
    }
    String tableName=entity.getTable().getName();
    String entityType=getUnqualifiedEntityName(tableName) + TYPE_STR;
    List<IdAccessor> ids=entity.getAttributes().getIds();
    List<BasicAccessor> basics=entity.getAttributes().getBasics();
    List<MappingAccessor> mappings=new ArrayList<MappingAccessor>();
    mappings.addAll(ids);
    mappings.addAll(basics);
    String pks=null;
    int pkCount=0;
    for (    IdAccessor pk : ids) {
      if (pkCount++ == 0) {
        pks=OPEN_BRACKET + pk.getName().toUpperCase() + EQUALS_BINDING1_STR;
      }
 else {
        pks=pks.concat(AND_STR + pk.getName().toUpperCase() + EQUALS_BINDING_STR+ pkCount++);
      }
    }
    if (pks != null) {
      pks=pks.concat(CLOSE_BRACKET);
    }
    NamedNativeQueryMetadata crudQuery=new NamedNativeQueryMetadata();
    crudQuery.setName(PK_QUERYNAME + UNDERSCORE + entityType);
    crudQuery.setQuery(SELECT_FROM_STR + tableName + WHERE_STR+ pks);
    entity.getNamedNativeQueries().add(crudQuery);
    crudQuery=new NamedNativeQueryMetadata();
    crudQuery.setName(ALL_QUERYNAME + UNDERSCORE + entityType);
    crudQuery.setQuery(SELECT_FROM_STR + tableName);
    entity.getNamedNativeQueries().add(crudQuery);
    String sqlStmt=INSERT_STR + tableName + SINGLE_SPACE+ OPEN_BRACKET;
    int idx=1;
    String cols="String_Node_Str";
    for (Iterator i=mappings.iterator(); i.hasNext(); ) {
      MappingAccessor mapping=(MappingAccessor)i.next();
      cols+=mapping.getName().toUpperCase();
      if (i.hasNext()) {
        cols+=COMMA_SPACE_STR;
      }
      idx++;
    }
    sqlStmt+=cols + CLOSE_BRACKET + VALUES_STR+ OPEN_BRACKET;
    String vals="String_Node_Str";
    for (int k=1; k < idx; k++) {
      vals+=QUESTION_STR + k;
      if (k + 1 < idx) {
        vals+=COMMA_SPACE_STR;
      }
    }
    sqlStmt+=vals + CLOSE_BRACKET;
    crudQuery=new NamedNativeQueryMetadata();
    crudQuery.setName(CREATE_OPERATION_NAME + UNDERSCORE + entityType);
    crudQuery.setQuery(sqlStmt);
    entity.getNamedNativeQueries().add(crudQuery);
    sqlStmt=UPDATE_STR + tableName + SET_STR;
    idx=pkCount;
    for (Iterator i=basics.iterator(); i.hasNext(); ) {
      BasicAccessor basic=(BasicAccessor)i.next();
      sqlStmt+=basic.getName().toUpperCase() + EQUALS_BINDING_STR + (++idx);
      if (i.hasNext()) {
        sqlStmt+=COMMA_SPACE_STR;
      }
    }
    sqlStmt+=WHERE_STR + pks;
    crudQuery=new NamedNativeQueryMetadata();
    crudQuery.setName(UPDATE_OPERATION_NAME + UNDERSCORE + entityType);
    crudQuery.setQuery(sqlStmt);
    entity.getNamedNativeQueries().add(crudQuery);
    crudQuery=new NamedNativeQueryMetadata();
    crudQuery.setName(REMOVE_OPERATION_NAME + UNDERSCORE + entityType);
    crudQuery.setQuery(DELETE_STR + tableName + WHERE_STR+ pks);
    entity.getNamedNativeQueries().add(crudQuery);
  }
}

Fixed version (ground truth):
/** 
 * Generates NamedNativeQueryMetadata for CRUD operations (create, findAll, findByPk, update and delete) for a given Entity if required, i.e. generateCRUDOps is true.
 */
@SuppressWarnings("String_Node_Str") protected void generateCRUDMetadata(EntityAccessor entity){
  if (generateCRUDOps) {
    if (entity.getNamedNativeQueries() == null) {
      entity.setNamedNativeQueries(new ArrayList<NamedNativeQueryMetadata>());
    }
    String tableName=entity.getTable().getName();
    String entityType=getUnqualifiedEntityName(tableName) + TYPE_STR;
    List<IdAccessor> ids=entity.getAttributes().getIds();
    List<BasicAccessor> basics=entity.getAttributes().getBasics();
    List<MappingAccessor> mappings=new ArrayList<MappingAccessor>();
    mappings.addAll(ids);
    mappings.addAll(basics);
    String pks=null;
    int pkCount=0;
    for (    IdAccessor pk : ids) {
      if (pkCount++ == 0) {
        pks=OPEN_BRACKET + pk.getName().toUpperCase() + EQUALS_BINDING1_STR;
      }
 else {
        pks=pks.concat(AND_STR + pk.getName().toUpperCase() + EQUALS_BINDING_STR+ pkCount++);
      }
    }
    if (pks != null) {
      pks=pks.concat(CLOSE_BRACKET);
    }
    NamedNativeQueryMetadata crudQuery=new NamedNativeQueryMetadata();
    crudQuery.setName(PK_QUERYNAME + UNDERSCORE + entityType);
    crudQuery.setQuery(SELECT_FROM_STR + tableName + WHERE_STR+ pks);
    crudQuery.setResultClassName(entity.getClassName());
    entity.getNamedNativeQueries().add(crudQuery);
    crudQuery=new NamedNativeQueryMetadata();
    crudQuery.setName(ALL_QUERYNAME + UNDERSCORE + entityType);
    crudQuery.setQuery(SELECT_FROM_STR + tableName);
    crudQuery.setResultClassName(entity.getClassName());
    entity.getNamedNativeQueries().add(crudQuery);
    String sqlStmt=INSERT_STR + tableName + SINGLE_SPACE+ OPEN_BRACKET;
    int idx=1;
    String cols="String_Node_Str";
    for (Iterator i=mappings.iterator(); i.hasNext(); ) {
      MappingAccessor mapping=(MappingAccessor)i.next();
      cols+=mapping.getName().toUpperCase();
      if (i.hasNext()) {
        cols+=COMMA_SPACE_STR;
      }
      idx++;
    }
    sqlStmt+=cols + CLOSE_BRACKET + VALUES_STR+ OPEN_BRACKET;
    String vals="String_Node_Str";
    for (int k=1; k < idx; k++) {
      vals+=QUESTION_STR + k;
      if (k + 1 < idx) {
        vals+=COMMA_SPACE_STR;
      }
    }
    sqlStmt+=vals + CLOSE_BRACKET;
    crudQuery=new NamedNativeQueryMetadata();
    crudQuery.setName(CREATE_OPERATION_NAME + UNDERSCORE + entityType);
    crudQuery.setQuery(sqlStmt);
    entity.getNamedNativeQueries().add(crudQuery);
    sqlStmt=UPDATE_STR + tableName + SET_STR;
    idx=pkCount;
    for (Iterator i=basics.iterator(); i.hasNext(); ) {
      BasicAccessor basic=(BasicAccessor)i.next();
      sqlStmt+=basic.getName().toUpperCase() + EQUALS_BINDING_STR + (++idx);
      if (i.hasNext()) {
        sqlStmt+=COMMA_SPACE_STR;
      }
    }
    sqlStmt+=WHERE_STR + pks;
    crudQuery=new NamedNativeQueryMetadata();
    crudQuery.setName(UPDATE_OPERATION_NAME + UNDERSCORE + entityType);
    crudQuery.setQuery(sqlStmt);
    entity.getNamedNativeQueries().add(crudQuery);
    crudQuery=new NamedNativeQueryMetadata();
    crudQuery.setName(REMOVE_OPERATION_NAME + UNDERSCORE + entityType);
    crudQuery.setQuery(DELETE_STR + tableName + WHERE_STR+ pks);
    entity.getNamedNativeQueries().add(crudQuery);
  }
}