Buggy code:
public class SearchModel { private static final SearchModel _default = new SearchModel ( ) ; private final DatabaseManager dbmanager = DatabaseManager . getDefault ( ) ; private static final int WHERE_DEFAULT_LENGTH = 6 ; private SearchModel ( ) { } public static SearchModel getDefault ( ) { } public List < Luggage > initSearch ( Luggage luggage , LocalDate beginDate , LocalDate endDate ) { String searchQuery = "SELECT<seq2seq4repair_space>luggage.id<seq2seq4repair_space>FROM<seq2seq4repair_space>luggage<seq2seq4repair_space>{JOIN}<seq2seq4repair_space>{WHERE}" ; String whereQuery = "WHERE<seq2seq4repair_space>" ; String innerjoinQuery = "" ; if ( null != ( luggage . airport ) ) { if ( ( luggage . airport . getID ( ) ) != 0 ) { innerjoinQuery += "INNER<seq2seq4repair_space>JOIN<seq2seq4repair_space>airport<seq2seq4repair_space>ON<seq2seq4repair_space>luggage.airport_id<seq2seq4repair_space>=<seq2seq4repair_space>airport.id<seq2seq4repair_space>" ; whereQuery += ( "<seq2seq4repair_space>airport.name<seq2seq4repair_space>=<seq2seq4repair_space>'" + ( luggage . airport . getName ( ) ) ) + "'" ; } } if ( null != ( luggage . color ) ) { if ( ( luggage . color . getID ( ) ) != 0 ) { Log . display ( luggage . color . getID ( ) ) ; innerjoinQuery += "INNER<seq2seq4repair_space>JOIN<seq2seq4repair_space>color<seq2seq4repair_space>ON<seq2seq4repair_space>luggage.color_id<seq2seq4repair_space>=<seq2seq4repair_space>color.id<seq2seq4repair_space>" ; if ( ( whereQuery . length ( ) ) > ( SearchModel . WHERE_DEFAULT_LENGTH ) ) { whereQuery += "<seq2seq4repair_space>AND" ; } whereQuery += ( "<seq2seq4repair_space>color.name<seq2seq4repair_space>=<seq2seq4repair_space>'" + ( luggage . color . getHex ( ) ) ) + "'<seq2seq4repair_space>" ; } } if ( null != ( luggage . brand ) ) { <START_BUG> innerjoinQuery += "INNER<seq2seq4repair_space>JOIN<seq2seq4repair_space>brand.id<seq2seq4repair_space>ON<seq2seq4repair_space>luggage.brand_id=brand.id" ; <END_BUG> if ( ( whereQuery . length ( ) ) > ( SearchModel . WHERE_DEFAULT_LENGTH ) ) { whereQuery += "<seq2seq4repair_space>AND" ; } whereQuery += ( "<seq2seq4repair_space>brand.name<seq2seq4repair_space>=<seq2seq4repair_space>'" + ( luggage . brand . getName ( ) ) ) + "'<seq2seq4repair_space>" ; } if ( ! ( luggage . label . isEmpty ( ) ) ) { if ( ( whereQuery . length ( ) ) > 0 ) { whereQuery += "<seq2seq4repair_space>AND" ; } whereQuery += ( "<seq2seq4repair_space>luggage.label<seq2seq4repair_space>LIKE<seq2seq4repair_space>'%" + ( luggage . label ) ) + "%'" ; } if ( ! ( luggage . notes . isEmpty ( ) ) ) { if ( ( whereQuery . length ( ) ) > ( SearchModel . WHERE_DEFAULT_LENGTH ) ) { whereQuery += "<seq2seq4repair_space>AND" ; } whereQuery += ( "<seq2seq4repair_space>luggage.notes<seq2seq4repair_space>LIKE<seq2seq4repair_space>'%" + ( luggage . notes ) ) + "%'" ; } if ( ! ( luggage . weight . isEmpty ( ) ) ) { if ( ( whereQuery . length ( ) ) > ( SearchModel . WHERE_DEFAULT_LENGTH ) ) { whereQuery += "<seq2seq4repair_space>AND" ; } whereQuery += ( "<seq2seq4repair_space>luggage.weight<seq2seq4repair_space>LIKE<seq2seq4repair_space>'%" + ( luggage . weight ) ) + "%'" ; } if ( ! ( "xx<seq2seq4repair_space>cm" . equals ( luggage . dimensions ) ) ) { if ( ( whereQuery . length ( ) ) > ( SearchModel . WHERE_DEFAULT_LENGTH ) ) { whereQuery += "<seq2seq4repair_space>AND" ; } whereQuery += ( "<seq2seq4repair_space>luggage.dimensions<seq2seq4repair_space>LIKE<seq2seq4repair_space>'%" + ( luggage . dimensions ) ) + "%'" ; } if ( ( null != beginDate ) && ( null != endDate ) ) { if ( ( whereQuery . length ( ) ) > ( SearchModel . WHERE_DEFAULT_LENGTH ) ) { whereQuery += "<seq2seq4repair_space>AND" ; } whereQuery += ( ( ( "<seq2seq4repair_space>(DATE_FORMAT(FROM_UNIXTIME(create_date),<seq2seq4repair_space>'%Y-%m-%d')<seq2seq4repair_space>BETWEEN<seq2seq4repair_space>'" + beginDate ) + "'<seq2seq4repair_space>AND<seq2seq4repair_space>'" ) + endDate ) + "')" ; } if ( null != ( luggage . status ) ) { if ( ( whereQuery . length ( ) ) > ( SearchModel . WHERE_DEFAULT_LENGTH ) ) { whereQuery += "<seq2seq4repair_space>AND" ; } whereQuery += "<seq2seq4repair_space>luggage.status_id<seq2seq4repair_space>=<seq2seq4repair_space>" + ( luggage . status . getID ( ) ) ; } searchQuery = searchQuery . replace ( "{JOIN}" , innerjoinQuery ) ; String replaceValue = ( ( whereQuery . length ( ) ) > ( SearchModel . WHERE_DEFAULT_LENGTH ) ) ? whereQuery : "" ; searchQuery = searchQuery . replace ( "{WHERE}" , replaceValue ) ; Log . display ( whereQuery . length ( ) , whereQuery , searchQuery ) ; List < Luggage > luggages = executeQuery ( searchQuery ) ; return luggages ; } private List < Luggage > executeQuery ( String query ) { } }

Fix:
innerjoinQuery += "INNER<seq2seq4repair_space>JOIN<seq2seq4repair_space>brand<seq2seq4repair_space>ON<seq2seq4repair_space>luggage.brand_id=brand.id" ;