Buggy code:
String order = request . getParameter ( "order" ) ; Integer page ; Integer resultsPerPage ; try { if ( ! ( ( ( ( ( ( ( searchBy . equals ( "title" ) ) || ( searchBy . equals ( "letter" ) ) ) || ( searchBy . equals ( "genre" ) ) ) || ( searchBy . equals ( "year" ) ) ) || ( searchBy . equals ( "director" ) ) ) || ( searchBy . equals ( "first_name" ) ) ) || ( searchBy . equals ( "last_name" ) ) ) ) { searchBy = "title" ; } } catch ( NullPointerException e ) { searchBy = "title" ; } if ( arg == null ) { arg = "" ; } if ( searchBy . equals ( "letter" ) ) { if ( arg . isEmpty ( ) ) { arg = "<seq2seq4repair_space>" ; } else { arg = arg . substring ( 0 , 1 ) ; } } if ( searchBy . equals ( "title" ) ) { try { Pattern . compile ( arg ) ; } catch ( PatternSyntaxException exception ) { arg = "" ; } } String sortBy = "" ; try { if ( order . equals ( "t_d" ) ) { sortBy = "ORDER<seq2seq4repair_space>BY<seq2seq4repair_space>title<seq2seq4repair_space>DESC" ; } else if ( order . equals ( "y_d" ) ) { sortBy = "ORDER<seq2seq4repair_space>BY<seq2seq4repair_space>year<seq2seq4repair_space>DESC" ; } else if ( order . equals ( "y_a" ) ) { sortBy = "ORDER<seq2seq4repair_space>BY<seq2seq4repair_space>year" ; } else { sortBy = "ORDER<seq2seq4repair_space>BY<seq2seq4repair_space>title" ; order = "t_a" ; } } catch ( NullPointerException e ) { sortBy = "ORDER<seq2seq4repair_space>BY<seq2seq4repair_space>title" ; order = "t_a" ; } try { page = Integer . valueOf ( request . getParameter ( "page" ) ) ; if ( page < 1 ) { page = 1 ; } } catch ( NumberFormatException e ) { page = 1 ; } catch ( NullPointerException e ) { page = 1 ; } try { resultsPerPage = Integer . valueOf ( request . getParameter ( "rpp" ) ) ; if ( resultsPerPage < 1 ) { resultsPerPage = 5 ; } } catch ( NumberFormatException e ) { resultsPerPage = 5 ; } catch ( NullPointerException e ) { resultsPerPage = 5 ; } int listStart ; if ( page > 0 ) { listStart = ( page - 1 ) * resultsPerPage ; } else { listStart = 0 ; page = 1 ; } Statement statement = dbcon . createStatement ( ) ; Statement fullStatement = dbcon . createStatement ( ) ; String query ; String fullQuery ; if ( arg . isEmpty ( ) ) { <START_BUG> query = ( ( ( ( "SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>m.id,title,year,director,banner_url<seq2seq4repair_space>FROM<seq2seq4repair_space>movies<seq2seq4repair_space>" + sortBy ) + "<seq2seq4repair_space>LIMIT<seq2seq4repair_space>" ) + listStart ) + "," ) + resultsPerPage ; <END_BUG> fullQuery = "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>(SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>*<seq2seq4repair_space>FROM<seq2seq4repair_space>movies)<seq2seq4repair_space>AS<seq2seq4repair_space>results" ; } else if ( searchBy . equals ( "genre" ) ) { query = ( ( ( ( ( ( "SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>m.id,title,year,director,banner_url<seq2seq4repair_space>FROM<seq2seq4repair_space>movies<seq2seq4repair_space>m<seq2seq4repair_space>LEFT<seq2seq4repair_space>OUTER<seq2seq4repair_space>JOIN<seq2seq4repair_space>genres_in_movies<seq2seq4repair_space>g<seq2seq4repair_space>ON<seq2seq4repair_space>g.movie_id=m.id<seq2seq4repair_space>LEFT<seq2seq4repair_space>OUTER<seq2seq4repair_space>JOIN<seq2seq4repair_space>genres<seq2seq4repair_space>gr<seq2seq4repair_space>ON<seq2seq4repair_space>g.genre_id=gr.id<seq2seq4repair_space>WHERE<seq2seq4repair_space>name<seq2seq4repair_space>=<seq2seq4repair_space>'" + arg ) + "'<seq2seq4repair_space>" ) + sortBy ) + "<seq2seq4repair_space>LIMIT<seq2seq4repair_space>" ) + listStart ) + "," ) + resultsPerPage ; fullQuery = ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>(SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>m.id<seq2seq4repair_space>FROM<seq2seq4repair_space>movies<seq2seq4repair_space>m<seq2seq4repair_space>LEFT<seq2seq4repair_space>OUTER<seq2seq4repair_space>JOIN<seq2seq4repair_space>genres_in_movies<seq2seq4repair_space>g<seq2seq4repair_space>ON<seq2seq4repair_space>g.movie_id=m.id<seq2seq4repair_space>LEFT<seq2seq4repair_space>OUTER<seq2seq4repair_space>JOIN<seq2seq4repair_space>genres<seq2seq4repair_space>gr<seq2seq4repair_space>ON<seq2seq4repair_space>g.genre_id=gr.id<seq2seq4repair_space>WHERE<seq2seq4repair_space>name<seq2seq4repair_space>=<seq2seq4repair_space>'" + arg ) + "')<seq2seq4repair_space>as<seq2seq4repair_space>results" ; } else if ( searchBy . equals ( "letter" ) ) { query = ( ( ( ( ( ( "SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>m.id,title,year,director,banner_url<seq2seq4repair_space>FROM<seq2seq4repair_space>movies<seq2seq4repair_space>m<seq2seq4repair_space>WHERE<seq2seq4repair_space>title<seq2seq4repair_space>REGEXP<seq2seq4repair_space>'^" + arg ) + "'<seq2seq4repair_space>" ) + sortBy ) + "<seq2seq4repair_space>LIMIT<seq2seq4repair_space>" ) + listStart ) + "," ) + resultsPerPage ; fullQuery = ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>(SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>m.id<seq2seq4repair_space>FROM<seq2seq4repair_space>movies<seq2seq4repair_space>m<seq2seq4repair_space>WHERE<seq2seq4repair_space>title<seq2seq4repair_space>REGEXP<seq2seq4repair_space>'^" + arg ) + "')<seq2seq4repair_space>as<seq2seq4repair_space>results" ; } else if ( searchBy . equals ( "title" ) ) { query = ( ( ( ( ( ( "SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>m.id,title,year,director,banner_url<seq2seq4repair_space>FROM<seq2seq4repair_space>movies<seq2seq4repair_space>m<seq2seq4repair_space>WHERE<seq2seq4repair_space>title<seq2seq4repair_space>REGEXP<seq2seq4repair_space>'" + arg ) + "'<seq2seq4repair_space>" ) + sortBy ) + "<seq2seq4repair_space>LIMIT<seq2seq4repair_space>" ) + listStart ) + "," ) + resultsPerPage ; fullQuery = ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>(SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>m.id<seq2seq4repair_space>FROM<seq2seq4repair_space>movies<seq2seq4repair_space>m<seq2seq4repair_space>WHERE<seq2seq4repair_space>title<seq2seq4repair_space>REGEXP<seq2seq4repair_space>'" + arg ) + "')<seq2seq4repair_space>as<seq2seq4repair_space>results" ; } else if ( ( searchBy . equals ( "first_name" ) ) || ( searchBy . equals ( "last_name" ) ) ) { query = ( ( ( ( ( ( ( ( "SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>m.id,title,year,director,banner_url<seq2seq4repair_space>FROM<seq2seq4repair_space>movies<seq2seq4repair_space>m<seq2seq4repair_space>LEFT<seq2seq4repair_space>OUTER<seq2seq4repair_space>JOIN<seq2seq4repair_space>stars_in_movies<seq2seq4repair_space>s<seq2seq4repair_space>ON<seq2seq4repair_space>movie_id=m.id<seq2seq4repair_space>LEFT<seq2seq4repair_space>OUTER<seq2seq4repair_space>JOIN<seq2seq4repair_space>stars<seq2seq4repair_space>s1<seq2seq4repair_space>ON<seq2seq4repair_space>s.star_id=s1.id<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + searchBy ) + "<seq2seq4repair_space>=<seq2seq4repair_space>'" ) + arg ) + "'<seq2seq4repair_space>" ) + sortBy ) + "<seq2seq4repair_space>LIMIT<seq2seq4repair_space>" ) + listStart ) + "," ) + resultsPerPage ; fullQuery = ( ( ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>(SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>m.id<seq2seq4repair_space>FROM<seq2seq4repair_space>movies<seq2seq4repair_space>m<seq2seq4repair_space>LEFT<seq2seq4repair_space>OUTER<seq2seq4repair_space>JOIN<seq2seq4repair_space>stars_in_movies<seq2seq4repair_space>s<seq2seq4repair_space>ON<seq2seq4repair_space>movie_id=m.id<seq2seq4repair_space>LEFT<seq2seq4repair_space>OUTER<seq2seq4repair_space>JOIN<seq2seq4repair_space>stars<seq2seq4repair_space>s1<seq2seq4repair_space>ON<seq2seq4repair_space>s.star_id=s1.id<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + searchBy ) + "<seq2seq4repair_space>=<seq2seq4repair_space>'" ) + arg ) + "')<seq2seq4repair_space>as<seq2seq4repair_space>results" ; } else { query = ( ( ( ( ( ( ( ( "SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>m.id,title,year,director,banner_url<seq2seq4repair_space>FROM<seq2seq4repair_space>movies<seq2seq4repair_space>m<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + searchBy ) + "<seq2seq4repair_space>=<seq2seq4repair_space>'" ) + arg ) + "'<seq2seq4repair_space>" ) + sortBy ) + "<seq2seq4repair_space>LIMIT<seq2seq4repair_space>" ) + listStart ) + "," ) + resultsPerPage ; fullQuery = ( ( ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>(SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>m.id<seq2seq4repair_space>FROM<seq2seq4repair_space>movies<seq2seq4repair_space>m<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + searchBy ) + "<seq2seq4repair_space>=<seq2seq4repair_space>'" ) + arg ) + "')<seq2seq4repair_space>as<seq2seq4repair_space>results" ; } ResultSet searchResults = statement . executeQuery ( query ) ; ResultSet fullCount = fullStatement . executeQuery ( fullQuery ) ; fullCount . next ( ) ; int numberOfResults = fullCount . getInt ( 1 ) ; int numberOfPages = ( numberOfResults // resultsPerPage ) + ( ( numberOfResults % resultsPerPage ) == 0 ? 0 : 1 ) ; if ( ( numberOfResults > 0 ) && ( page > numberOfPages ) ) { response . sendRedirect ( ( ( ( ( ( ( ( ( ( "ListResults?by=" + searchBy ) + "&arg=" ) + ( URLEncoder . encode ( arg , "UTF-8" ) ) ) + "&page=" ) + numberOfPages ) + "&rpp=" ) + resultsPerPage ) + "&order=" ) + order ) ) ; } out . println ( ( ( ( ( "<HTML><HEAD><TITLE>FabFlix<seq2seq4repair_space>--<seq2seq4repair_space>Search<seq2seq4repair_space>by<seq2seq4repair_space>" + searchBy ) + ":<seq2seq4repair_space>" ) + arg ) + "<//TITLE><//HEAD><BODY>" ) ) ; ListResults . header ( request , out , resultsPerPage ) ; out . println ( ( ( ( ( "<H2>Search<seq2seq4repair_space>by<seq2seq4repair_space>" + searchBy ) + ":<seq2seq4repair_space>" ) + arg ) + "<//H2>" ) ) ; out . println ( "<BR>" ) ; if ( numberOfResults > 0 ) { out . println ( ( ( "(<seq2seq4repair_space>" + numberOfResults ) + "<seq2seq4repair_space>Results<seq2seq4repair_space>)" ) ) ; showRppOptions ( out , searchBy , arg , order , page , resultsPerPage ) ;

Fix:
query = ( ( ( ( "SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>m.id,title,year,director,banner_url<seq2seq4repair_space>FROM<seq2seq4repair_space>movies<seq2seq4repair_space>m<seq2seq4repair_space>" + sortBy ) + "<seq2seq4repair_space>LIMIT<seq2seq4repair_space>" ) + listStart ) + "," ) + resultsPerPage ;