Buggy code:
public class PostgresqlStore implements Store { private final DBInfo dbInfo ; private Database database ; private final DatabaseSchema databaseSchema ; public PostgresqlStore ( DBInfo dbInfo , DataSource dataSource ) { } @ Override public void save ( Record record ) { } @ Override public void update ( String oldhash , Record record ) { } @ Override public void deleteAll ( ) { } @ Override public Optional < Record > findByKV ( String key , String value ) { } @ Override public List < RecordVersionInfo > previousVersions ( String hash ) { } @ Override public Optional < Record > findByHash ( String hash ) { } @ SuppressWarnings ( "StringConcatenationInsideStringBufferAppend" ) @ Override public List < Record > search ( Map < String , String > map , int offset , int limit , boolean historic , boolean exact ) { final StringBuilder sqlBuilder = new StringBuilder ( "" ) ; if ( ! ( map . isEmpty ( ) ) ) { sqlBuilder . append ( "<seq2seq4repair_space>WHERE<seq2seq4repair_space>" ) ; if ( exact ) { sqlBuilder . append ( map . keySet ( ) . stream ( ) . map ( ( k ) -> String . format ( "entry<seq2seq4repair_space>@><seq2seq4repair_space>\'{\"%s\"=\"%s\"}\'" , k , map . get ( k ) ) ) . collect ( Collectors . joining ( "<seq2seq4repair_space>AND<seq2seq4repair_space>" ) ) ) ; } else { <START_BUG> sqlBuilder . append ( ( ( ( ( "hash<seq2seq4repair_space>in<seq2seq4repair_space>(SELECT<seq2seq4repair_space>hash<seq2seq4repair_space>FROM<seq2seq4repair_space>" + ( dbInfo . tableName ) ) + "<seq2seq4repair_space>WHERE<seq2seq4repair_space>searchable<seq2seq4repair_space>@@<seq2seq4repair_space>to_tsquery('" ) + ( map . values ( ) . stream ( ) . collect ( Collectors . joining ( "&" ) ) ) ) + "'))" ) ) ; <END_BUG> map . forEach ( ( k , v ) -> sqlBuilder . append ( ( ( ( ( "<seq2seq4repair_space>AND<seq2seq4repair_space>entry->>'" + k ) + "'<seq2seq4repair_space>ILIKE<seq2seq4repair_space>'%" ) + ( map . get ( k ) ) ) + "%'" ) ) ) ; } } return executeSearch ( sqlBuilder . toString ( ) , offset , limit , historic ) ; } @ Override public List < Record > search ( String query , int offset , int limit , boolean historic ) { } private List < Record > executeSearch ( String where , int offset , int limit , boolean historic ) { } @ Override public long count ( ) { } @ Override public void fastImport ( List < Record > records ) { } @ SuppressWarnings ( "unchecked" ) public static String canonicalizeEntryText ( JsonNode entry ) { } private Object primaryKeyValue ( Record record ) { } private PGobject createPGObject ( String data ) { } private Optional < Record > toOptionalRecord ( ResultSet resultSet ) throws IOException , SQLException { } private Record toRecord ( ResultSet resultSet ) throws IOException , SQLException { } private List < Record > getRecords ( ResultSet resultSet ) throws IOException , SQLException { } }

Fix:
sqlBuilder . append ( ( ( ( ( "hash<seq2seq4repair_space>in<seq2seq4repair_space>(SELECT<seq2seq4repair_space>hash<seq2seq4repair_space>FROM<seq2seq4repair_space>" + ( dbInfo . tableName ) ) + "<seq2seq4repair_space>WHERE<seq2seq4repair_space>searchable<seq2seq4repair_space>@@<seq2seq4repair_space>to_tsquery('" ) + ( map . values ( ) . stream ( ) . collect ( Collectors . joining ( "&" ) ) . replaceAll ( "\\s" , "&" ) ) ) + "'))" ) ) ;