Buggy code:
@ Repository public class SchemaDAOImpl extends GeneralDAOImpl implements ISchemaDAO { private static final Logger LOGGER = Logger . getLogger ( SchemaDAOImpl . class ) ; private static final String REPLACE_ID_SQL = "update<seq2seq4repair_space>T_SCHEMA<seq2seq4repair_space>set<seq2seq4repair_space>SCHEMA_ID=:substituteId<seq2seq4repair_space>where<seq2seq4repair_space>SCHEMA_ID=:replacedId" ; private static final String INSERT_SQL = "insert<seq2seq4repair_space>into<seq2seq4repair_space>T_SCHEMA<seq2seq4repair_space>(FILENAME,<seq2seq4repair_space>SCHEMA_SET_ID,<seq2seq4repair_space>CONTINUITY_ID,<seq2seq4repair_space>REG_STATUS,<seq2seq4repair_space>" + ( ( "WORKING_COPY,<seq2seq4repair_space>WORKING_USER,<seq2seq4repair_space>DATE_MODIFIED,<seq2seq4repair_space>USER_MODIFIED,<seq2seq4repair_space>COMMENT,<seq2seq4repair_space>CHECKEDOUT_COPY_ID,<seq2seq4repair_space>OTHER_DOCUMENT)<seq2seq4repair_space>" + "values<seq2seq4repair_space>(:filename,:schemaSetId,:continuityId,:regStatus,:workingCopy," ) + ":workingUser,now(),:userModified,:comment,:checkedOutCopyId,:otherDocument)" ) ; private static final String LIST_FOR_SCHEMA_SET = "select<seq2seq4repair_space>*<seq2seq4repair_space>from<seq2seq4repair_space>T_SCHEMA<seq2seq4repair_space>where<seq2seq4repair_space>SCHEMA_SET_ID=:schemaSetId<seq2seq4repair_space>order<seq2seq4repair_space>by<seq2seq4repair_space>FILENAME" ; private static final String COPY_TO_SCHEMA_SET_SQL = "insert<seq2seq4repair_space>into<seq2seq4repair_space>T_SCHEMA<seq2seq4repair_space>(FILENAME,<seq2seq4repair_space>SCHEMA_SET_ID,<seq2seq4repair_space>DATE_MODIFIED,<seq2seq4repair_space>USER_MODIFIED,<seq2seq4repair_space>OTHER_DOCUMENT)<seq2seq4repair_space>" + ( "select<seq2seq4repair_space>ifnull(:newFileName,FILENAME),<seq2seq4repair_space>ifnull(:schemaSetId,SCHEMA_SET_ID),<seq2seq4repair_space>now()," + ":userName,<seq2seq4repair_space>OTHER_DOCUMENT<seq2seq4repair_space>from<seq2seq4repair_space>T_SCHEMA<seq2seq4repair_space>where<seq2seq4repair_space>SCHEMA_ID=:schemaId" ) ; private static final String GET_WORKING_COPIES_SQL = "select<seq2seq4repair_space>*<seq2seq4repair_space>from<seq2seq4repair_space>T_SCHEMA<seq2seq4repair_space>where<seq2seq4repair_space>WORKING_COPY=true<seq2seq4repair_space>and<seq2seq4repair_space>WORKING_USER=:userName<seq2seq4repair_space>order<seq2seq4repair_space>by<seq2seq4repair_space>FILENAME<seq2seq4repair_space>asc" ; private static final String SET_WORKING_USER_SQL = "update<seq2seq4repair_space>T_SCHEMA<seq2seq4repair_space>set<seq2seq4repair_space>WORKING_USER=:userName<seq2seq4repair_space>where<seq2seq4repair_space>SCHEMA_ID=:schemaId" ; private static final String COPY_SCHEMA_ROW = "insert<seq2seq4repair_space>into<seq2seq4repair_space>T_SCHEMA<seq2seq4repair_space>" + ( ( "(FILENAME,<seq2seq4repair_space>CONTINUITY_ID,<seq2seq4repair_space>WORKING_COPY,<seq2seq4repair_space>WORKING_USER,<seq2seq4repair_space>USER_MODIFIED,<seq2seq4repair_space>CHECKEDOUT_COPY_ID,<seq2seq4repair_space>REG_STATUS,<seq2seq4repair_space>OTHER_DOCUMENT)" + "<seq2seq4repair_space>select<seq2seq4repair_space>ifnull(:fileName,FILENAME),<seq2seq4repair_space>CONTINUITY_ID,<seq2seq4repair_space>true,<seq2seq4repair_space>:userName,<seq2seq4repair_space>:userName,<seq2seq4repair_space>:checkedOutCopyId,<seq2seq4repair_space>:regStatus,<seq2seq4repair_space>OTHER_DOCUMENT" ) + "<seq2seq4repair_space>from<seq2seq4repair_space>T_SCHEMA<seq2seq4repair_space>where<seq2seq4repair_space>SCHEMA_ID=:schemaId" ) ; private static final String GET_WORKING_COPY_OF_SQL = "select<seq2seq4repair_space>*<seq2seq4repair_space>from<seq2seq4repair_space>T_SCHEMA<seq2seq4repair_space>where<seq2seq4repair_space>(SCHEMA_SET_ID<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>or<seq2seq4repair_space>SCHEMA_SET_ID<=0)" + "<seq2seq4repair_space>and<seq2seq4repair_space>WORKING_COPY=true<seq2seq4repair_space>and<seq2seq4repair_space>CHECKEDOUT_COPY_ID<seq2seq4repair_space>=<seq2seq4repair_space>:checkedOutCopyId" ; @ Override public int createSchema ( Schema schema ) { } @ Override public List < Schema > listForSchemaSet ( int schemaSetId ) { } @ Override public List < Schema > listForSchemaSets ( List < SchemaSet > schemaSets ) { } @ Override public int copyToSchemaSet ( int schemaId , int schemaSetId , String fileName , String userName ) { } @ Override public void replaceId ( int replacedId , int substituteId ) { } @ Override public List < Schema > getSchemas ( List < Integer > ids ) { } @ Override public void deleteSchemas ( List < Integer > ids ) { } @ Override public List < Integer > getSchemaIds ( List < Integer > schemaSetIds ) { } @ Override public SchemasResult searchSchemas ( SchemaFilter searchFilter ) { int nameAttrId = getNameAttributeId ( ) ; <START_BUG> StringBuilder sql = new StringBuilder ( ) . append ( "select<seq2seq4repair_space>" ) . append ( "S.*,<seq2seq4repair_space>SS.*,<seq2seq4repair_space>ATR1.VALUE<seq2seq4repair_space>as<seq2seq4repair_space>NAME_ATTR,<seq2seq4repair_space>atr2.VALUE<seq2seq4repair_space>as<seq2seq4repair_space>SS_NAME_ATTR,<seq2seq4repair_space>" ) . append ( "if(SS.SCHEMA_SET_ID<seq2seq4repair_space>is<seq2seq4repair_space>null,<seq2seq4repair_space>S.WORKING_COPY,<seq2seq4repair_space>SS.WORKING_COPY)<seq2seq4repair_space>as<seq2seq4repair_space>WCOPY,<seq2seq4repair_space>" ) . append ( "if(SS.SCHEMA_SET_ID<seq2seq4repair_space>is<seq2seq4repair_space>null,<seq2seq4repair_space>S.WORKING_USER,<seq2seq4repair_space>SS.WORKING_USER)<seq2seq4repair_space>as<seq2seq4repair_space>WUSER,<seq2seq4repair_space>" ) . append ( "if(SS.SCHEMA_SET_ID<seq2seq4repair_space>is<seq2seq4repair_space>null,<seq2seq4repair_space>S.REG_STATUS,<seq2seq4repair_space>SS.REG_STATUS)<seq2seq4repair_space>as<seq2seq4repair_space>REGSTAT<seq2seq4repair_space>" ) . append ( "from<seq2seq4repair_space>" ) . append ( "T_SCHEMA<seq2seq4repair_space>as<seq2seq4repair_space>S<seq2seq4repair_space>left<seq2seq4repair_space>outer<seq2seq4repair_space>join<seq2seq4repair_space>T_SCHEMA_SET<seq2seq4repair_space>as<seq2seq4repair_space>SS<seq2seq4repair_space>on<seq2seq4repair_space>(S.SCHEMA_SET_ID=SS.SCHEMA_SET_ID)<seq2seq4repair_space>" ) . append ( "left<seq2seq4repair_space>outer<seq2seq4repair_space>join<seq2seq4repair_space>ATTRIBUTE<seq2seq4repair_space>as<seq2seq4repair_space>ATR1<seq2seq4repair_space>on<seq2seq4repair_space>" ) . append ( "(S.SCHEMA_ID=ATR1.DATAELEM_ID<seq2seq4repair_space>and<seq2seq4repair_space>ATR1.PARENT_TYPE=:attrParentType1<seq2seq4repair_space>" ) . append ( "and<seq2seq4repair_space>ATR1.M_ATTRIBUTE_ID=:nameAttrId)<seq2seq4repair_space>" ) . append ( "left<seq2seq4repair_space>outer<seq2seq4repair_space>join<seq2seq4repair_space>ATTRIBUTE<seq2seq4repair_space>as<seq2seq4repair_space>atr2<seq2seq4repair_space>on<seq2seq4repair_space>" ) . append ( "(S.SCHEMA_SET_ID=atr2.DATAELEM_ID<seq2seq4repair_space>and<seq2seq4repair_space>atr2.PARENT_TYPE=:attrParentType2<seq2seq4repair_space>" ) . append ( "and<seq2seq4repair_space>atr2.M_ATTRIBUTE_ID=:nameAttrId)<seq2seq4repair_space>" ) . append ( "where<seq2seq4repair_space>1=1<seq2seq4repair_space>" ) ; <END_BUG> String searchingUser = searchFilter . getSearchingUser ( ) ; Map < String , Object > params = new HashMap < String , Object > ( ) ; params . put ( "attrParentType1" , SCHEMA . toString ( ) ) ; params . put ( "attrParentType2" , SCHEMA_SET . toString ( ) ) ; params . put ( "nameAttrId" , nameAttrId ) ; if ( searchFilter . isValued ( ) ) { if ( StringUtils . isNotEmpty ( searchFilter . getFileName ( ) ) ) { sql . append ( "and<seq2seq4repair_space>S.FILENAME<seq2seq4repair_space>like<seq2seq4repair_space>:fileName<seq2seq4repair_space>" ) ; params . put ( "fileName" , ( ( "%" + ( searchFilter . getFileName ( ) ) ) + "%" ) ) ; } if ( StringUtils . isNotEmpty ( searchFilter . getSchemaSetIdentifier ( ) ) ) { sql . append ( "and<seq2seq4repair_space>SS.IDENTIFIER<seq2seq4repair_space>like<seq2seq4repair_space>:schemaSetIdentifier<seq2seq4repair_space>" ) ; params . put ( "schemaSetIdentifier" , ( ( "%" + ( searchFilter . getSchemaSetIdentifier ( ) ) ) + "%" ) ) ; } if ( searchFilter . isAttributesValued ( ) ) { for ( int i = 0 ; i < ( searchFilter . getAttributes ( ) . size ( ) ) ; i ++ ) { Attribute a = searchFilter . getAttributes ( ) . get ( i ) ; String idKey = "attrId" + i ; String valueKey = "attrValue" + i ; if ( StringUtils . isNotEmpty ( a . getValue ( ) ) ) { sql . append ( "and<seq2seq4repair_space>" ) ; sql . append ( "S.SCHEMA_ID<seq2seq4repair_space>IN<seq2seq4repair_space>(<seq2seq4repair_space>" ) ; sql . append ( "select<seq2seq4repair_space>A.DATAELEM_ID<seq2seq4repair_space>from<seq2seq4repair_space>ATTRIBUTE<seq2seq4repair_space>A<seq2seq4repair_space>where<seq2seq4repair_space>" ) ; sql . append ( ( ( ( ( "A.M_ATTRIBUTE_ID<seq2seq4repair_space>=<seq2seq4repair_space>:" + idKey ) + "<seq2seq4repair_space>and<seq2seq4repair_space>A.VALUE<seq2seq4repair_space>like<seq2seq4repair_space>:" ) + valueKey ) + "<seq2seq4repair_space>and<seq2seq4repair_space>A.PARENT_TYPE<seq2seq4repair_space>=<seq2seq4repair_space>:parentType<seq2seq4repair_space>" ) ) ; sql . append ( ")<seq2seq4repair_space>" ) ; } params . put ( idKey , a . getId ( ) ) ; String value = ( "%" + ( a . getValue ( ) ) ) + "%" ; params . put ( valueKey , value ) ; params . put ( "parentType" , SCHEMA . toString ( ) ) ; } } } if ( StringUtils . isBlank ( searchingUser ) ) { sql . append ( "having<seq2seq4repair_space>(WCOPY=false<seq2seq4repair_space>" ) ; if ( StringUtils . isEmpty ( searchFilter . getRegStatus ( ) ) ) { sql . append ( "AND<seq2seq4repair_space>REGSTAT<seq2seq4repair_space>IN<seq2seq4repair_space>(<seq2seq4repair_space>:regStatusPublic<seq2seq4repair_space>)<seq2seq4repair_space>" ) ; params . put ( "regStatusPublic" , RegStatus . getPublicStatuses ( ) ) ; } sql . append ( ")<seq2seq4repair_space>" ) ; } else { sql . append ( "having<seq2seq4repair_space>((WCOPY=false<seq2seq4repair_space>or<seq2seq4repair_space>WUSER=:workingUser)" ) ; params . put ( "workingUser" , searchingUser ) ; if ( StringUtils . isNotEmpty ( searchFilter . getRegStatus ( ) ) ) { sql . append ( "<seq2seq4repair_space>and<seq2seq4repair_space>REGSTAT=:regStatus" ) ; params . put ( "regStatus" , searchFilter . getRegStatus ( ) . toString ( ) ) ; } sql . append ( ")<seq2seq4repair_space>" ) ; } if ( StringUtils . isNotEmpty ( searchFilter . getSortProperty ( ) ) ) { sql . append ( "order<seq2seq4repair_space>by<seq2seq4repair_space>" ) . append ( searchFilter . getSortProperty ( ) ) ; if ( ASCENDING . equals ( searchFilter . getSortOrder ( ) ) ) { sql . append ( "<seq2seq4repair_space>asc<seq2seq4repair_space>" ) ; } else { sql . append ( "<seq2seq4repair_space>desc<seq2seq4repair_space>" ) ; } } if ( searchFilter . isUsePaging ( ) ) { sql . append ( "<seq2seq4repair_space>LIMIT<seq2seq4repair_space>" ) . append ( searchFilter . getOffset ( ) ) . append ( "," ) . append ( searchFilter . getPageSize ( ) ) ; } List < Schema > resultList = getNamedParameterJdbcTemplate ( ) . query ( sql . toString ( ) , params , new org . springframework . jdbc . core . RowMapper < Schema > ( ) { @ Override public Schema mapRow ( ResultSet rs , int rowNum ) throws SQLException { Schema schema = new Schema ( ) ; schema . setId ( rs . getInt ( "S.SCHEMA_ID" ) ) ; schema . setSchemaSetId ( rs . getInt ( "SS.SCHEMA_SET_ID" ) ) ;

Fix:
StringBuilder sql = new StringBuilder ( ) . append ( "select<seq2seq4repair_space>" ) . append ( "SQL_CALC_FOUND_ROWS<seq2seq4repair_space>S.*,<seq2seq4repair_space>SS.*,<seq2seq4repair_space>ATR1.VALUE<seq2seq4repair_space>as<seq2seq4repair_space>NAME_ATTR,<seq2seq4repair_space>atr2.VALUE<seq2seq4repair_space>as<seq2seq4repair_space>SS_NAME_ATTR,<seq2seq4repair_space>" ) . append ( "if(SS.SCHEMA_SET_ID<seq2seq4repair_space>is<seq2seq4repair_space>null,<seq2seq4repair_space>S.WORKING_COPY,<seq2seq4repair_space>SS.WORKING_COPY)<seq2seq4repair_space>as<seq2seq4repair_space>WCOPY,<seq2seq4repair_space>" ) . append ( "if(SS.SCHEMA_SET_ID<seq2seq4repair_space>is<seq2seq4repair_space>null,<seq2seq4repair_space>S.WORKING_USER,<seq2seq4repair_space>SS.WORKING_USER)<seq2seq4repair_space>as<seq2seq4repair_space>WUSER,<seq2seq4repair_space>" ) . append ( "if(SS.SCHEMA_SET_ID<seq2seq4repair_space>is<seq2seq4repair_space>null,<seq2seq4repair_space>S.REG_STATUS,<seq2seq4repair_space>SS.REG_STATUS)<seq2seq4repair_space>as<seq2seq4repair_space>REGSTAT<seq2seq4repair_space>" ) . append ( "from<seq2seq4repair_space>" ) . append ( "T_SCHEMA<seq2seq4repair_space>as<seq2seq4repair_space>S<seq2seq4repair_space>left<seq2seq4repair_space>outer<seq2seq4repair_space>join<seq2seq4repair_space>T_SCHEMA_SET<seq2seq4repair_space>as<seq2seq4repair_space>SS<seq2seq4repair_space>on<seq2seq4repair_space>(S.SCHEMA_SET_ID=SS.SCHEMA_SET_ID)<seq2seq4repair_space>" ) . append ( "left<seq2seq4repair_space>outer<seq2seq4repair_space>join<seq2seq4repair_space>ATTRIBUTE<seq2seq4repair_space>as<seq2seq4repair_space>ATR1<seq2seq4repair_space>on<seq2seq4repair_space>" ) . append ( "(S.SCHEMA_ID=ATR1.DATAELEM_ID<seq2seq4repair_space>and<seq2seq4repair_space>ATR1.PARENT_TYPE=:attrParentType1<seq2seq4repair_space>" ) . append ( "and<seq2seq4repair_space>ATR1.M_ATTRIBUTE_ID=:nameAttrId)<seq2seq4repair_space>" ) . append ( "left<seq2seq4repair_space>outer<seq2seq4repair_space>join<seq2seq4repair_space>ATTRIBUTE<seq2seq4repair_space>as<seq2seq4repair_space>atr2<seq2seq4repair_space>on<seq2seq4repair_space>" ) . append ( "(S.SCHEMA_SET_ID=atr2.DATAELEM_ID<seq2seq4repair_space>and<seq2seq4repair_space>atr2.PARENT_TYPE=:attrParentType2<seq2seq4repair_space>" ) . append ( "and<seq2seq4repair_space>atr2.M_ATTRIBUTE_ID=:nameAttrId)<seq2seq4repair_space>" ) . append ( "where<seq2seq4repair_space>1=1<seq2seq4repair_space>" ) ;