Buggy code:
@ Service public class ImageService extends BasicService { private static final Logger log = Logger . getLogger ( ImageService . class ) ; public ImageService ( String solrUrl ) { } public String getImage ( String term , String phenotype , String geneParameterToBeDeleted , String mutantGene , String anatomy , String expressedGene , String sex , String taxon , String image_type , String sample_type , String stage , String visualisationMethod , String samplePreparation , String imagingMethod , Integer rows , Integer start ) throws SolrServerException { SolrQuery solrQuery = new SolrQuery ( ) ; solrQuery . setQuery ( "*:*" ) ; if ( geneParameterToBeDeleted != null ) { mutantGene = geneParameterToBeDeleted ; } if ( term != null ) { solrQuery . setQuery ( ( ( ( ImageDTO . GENERIC_SEARCH ) + ":" ) + term ) ) ; if ( term . contains ( "<seq2seq4repair_space>" ) ) { String [ ] splittedQuery = term . split ( "<seq2seq4repair_space>" ) ; String query = ( ( ImageDTO . GENERIC_SEARCH ) + ":" ) + ( StringUtils . join ( splittedQuery , ( ( "^1<seq2seq4repair_space>" + ( ImageDTO . GENERIC_SEARCH ) ) + ":" ) ) ) ; solrQuery . set ( "defType" , "edismax" ) ; solrQuery . set ( "qf" , GENERIC_SEARCH ) ; solrQuery . set ( "bq" , ( ( ( ( ( ImageDTO . GENERIC_SEARCH ) + ":\"" ) + term ) + "\"^10<seq2seq4repair_space>" ) + query ) ) ; } else { solrQuery . addFilterQuery ( ( ( ( ImageDTO . GENERIC_SEARCH ) + ":" ) + term ) ) ; } } if ( phenotype != null ) { solrQuery . addFilterQuery ( ( ( ( ( ( ( ( ( ( ( ( ( ImageDTO . PHENOTYPE_ID_BAG ) + ":\"" ) + phenotype ) + "\"<seq2seq4repair_space>OR<seq2seq4repair_space>" ) + ( ImageDTO . PHENOTYPE_FREETEXT_BAG ) ) + ":\"" ) + phenotype ) + "\"<seq2seq4repair_space>OR<seq2seq4repair_space>" ) + ( ImageDTO . PHENOTYPE_LABEL_BAG ) ) + ":\"" ) + phenotype ) + "\"" ) ) ; } if ( mutantGene != null ) { solrQuery . addFilterQuery ( ( ( ( ( ( ( ( ( ImageDTO . GENE_ID ) + ":\"" ) + mutantGene ) + "\"<seq2seq4repair_space>OR<seq2seq4repair_space>" ) + ( ImageDTO . GENE_SYMBOL ) ) + ":\"" ) + mutantGene ) + "\"" ) ) ; } if ( anatomy != null ) { solrQuery . addFilterQuery ( ( ( ( ( ImageDTO . GENERIC_ANATOMY ) + ":\"" ) + anatomy ) + "\"" ) ) ; } if ( expressedGene != null ) { solrQuery . addFilterQuery ( ( ( ( ( ImageDTO . EXPRESSED_GF_ID_BAG ) + ":\"" ) + expressedGene ) + "\"" ) ) ; } if ( taxon != null ) { solrQuery . addFilterQuery ( ( ( ( ( ( ( ( ( ImageDTO . TAXON ) + ":\"" ) + taxon ) + "\"<seq2seq4repair_space>OR<seq2seq4repair_space>" ) + ( ImageDTO . NCBI_TAXON_ID ) ) + ":\"" ) + taxon ) + "\"" ) ) ; } if ( image_type != null ) { solrQuery . addFilterQuery ( ( ( ( ( ImageDTO . IMAGE_TYPE ) + ":\"" ) + image_type ) + "\"" ) ) ; } if ( sample_type != null ) { solrQuery . addFilterQuery ( ( ( ( ( ImageDTO . SAMPLE_TYPE ) + ":\"" ) + sample_type ) + "\"" ) ) ; } if ( stage != null ) { solrQuery . addFilterQuery ( ( ( ( ( ( ( ( ( ImageDTO . STAGE ) + ":\"" ) + stage ) + "\"<seq2seq4repair_space>OR<seq2seq4repair_space>" ) + ( ImageDTO . STAGE_ID ) ) + ":\"" ) + stage ) + "\"" ) ) ; } if ( visualisationMethod != null ) { solrQuery . addFilterQuery ( ( ( ( ( ( ( ( ( ImageDTO . VISUALISATION_METHOD_ID ) + ":\"" ) + visualisationMethod ) + "\"<seq2seq4repair_space>OR<seq2seq4repair_space>" ) + ( ImageDTO . VISUALISATION_METHOD_LABEL ) ) + ":\"" ) + visualisationMethod ) + "\"" ) ) ; } if ( samplePreparation != null ) { solrQuery . addFilterQuery ( ( ( ( ( ( ( ( ( ImageDTO . SAMPLE_PREPARATION_ID ) + ":\"" ) + samplePreparation ) + "\"<seq2seq4repair_space>OR<seq2seq4repair_space>" ) + ( ImageDTO . SAMPLE_PREPARATION_LABEL ) ) + ":\"" ) + samplePreparation ) + "\"" ) ) ; } <START_BUG> if ( samplePreparation != null ) { <END_BUG> solrQuery . addFilterQuery ( ( ( ( ( ( ( ( ( ImageDTO . IMAGING_METHOD_LABEL_ANALYSED ) + ":\"" ) + imagingMethod ) + "\"<seq2seq4repair_space>OR<seq2seq4repair_space>" ) + ( ImageDTO . IMAGING_METHOD_ID ) ) + ":\"" ) + imagingMethod ) + "\"" ) ) ; } if ( sex != null ) { solrQuery . addFilterQuery ( ( ( ( ( ImageDTO . SEX ) + ":\"" ) + sex ) + "\"" ) ) ; } if ( rows != null ) { solrQuery . setRows ( rows ) ; } else solrQuery . setRows ( 100 ) ; if ( start != null ) { solrQuery . set ( "start" , start ) ; } solrQuery . set ( "wt" , "json" ) ; solrQuery . setFacet ( true ) ; solrQuery . addFacetField ( STAGE ) ; solrQuery . addFacetField ( IMAGING_METHOD_LABEL ) ; solrQuery . addFacetField ( TAXON ) ; solrQuery . addFacetField ( SAMPLE_TYPE ) ; solrQuery . addFacetField ( IMAGE_GENERATED_BY ) ; solrQuery . set ( "facet.pivot.mincount" , 0 ) ; solrQuery . set ( "facet.pivot" , ( ( ( ImageDTO . SAMPLE_TYPE ) + "," ) + ( ImageDTO . IMAGE_TYPE ) ) ) ; System . out . println ( ( ( ( "\nSolr<seq2seq4repair_space>URL<seq2seq4repair_space>:<seq2seq4repair_space>" + ( solr . getBaseURL ( ) ) ) + "//select?" ) + solrQuery ) ) ; ImageService . log . info ( ( ( ( "Solr<seq2seq4repair_space>URL<seq2seq4repair_space>in<seq2seq4repair_space>getImages<seq2seq4repair_space>:<seq2seq4repair_space>" + ( solr . getBaseURL ( ) ) ) + "//select?" ) + solrQuery ) ) ; try { return JSONRestUtil . getResults ( getQueryUrl ( solrQuery ) ) . toString ( ) ; }

Fix:
if ( imagingMethod != null ) {