mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-14 15:53:36 +01:00
added additional null checks
Former-commit-id: 25acb44a1e8015da7c144e136c3a6adeb3992fb6
This commit is contained in:
@@ -38,6 +38,7 @@ import org.apache.lucene.search.TopDocs;
|
||||
import org.apache.lucene.util.Version;
|
||||
import org.owasp.dependencycheck.data.lucene.FieldAnalyzer;
|
||||
import org.owasp.dependencycheck.data.lucene.SearchFieldAnalyzer;
|
||||
import org.owasp.dependencycheck.data.update.BatchUpdate;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -119,6 +120,22 @@ public class CpeIndexReader extends BaseIndex {
|
||||
* Index
|
||||
*/
|
||||
public TopDocs search(String searchString, int maxQueryResults) throws ParseException, IOException {
|
||||
if (searchString == null || searchString.trim().isEmpty()) {
|
||||
throw new ParseException("Query is null or empty");
|
||||
}
|
||||
if (queryParser == null) {
|
||||
if (isOpen()) {
|
||||
final String msg = String.format("QueryParser is null for query: '%s'. Attempting to reopen index.", searchString);
|
||||
Logger.getLogger(CpeIndexReader.class.getName()).log(Level.WARNING, msg);
|
||||
close();
|
||||
open();
|
||||
} else {
|
||||
final String msg = String.format("QueryParser is null, but data source is open, for query: '%s'. Attempting to reopen index.", searchString);
|
||||
Logger.getLogger(CpeIndexReader.class.getName()).log(Level.WARNING, msg);
|
||||
close();
|
||||
open();
|
||||
}
|
||||
}
|
||||
final Query query = queryParser.parse(searchString);
|
||||
return indexSearcher.search(query, maxQueryResults);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user