Fix NPE in HighlightField serialization. Fixes #1380

This commit is contained in:
Igor Motov 2011-10-07 19:21:21 -04:00 committed by Shay Banon
parent 4bbe1b111a
commit bd87f8de3a
1 changed files with 3 additions and 3 deletions

View File

@ -169,9 +169,9 @@ public class HighlightPhase implements SearchHitPhase {
}
});
}
String[] fragments;
String[] fragments = null;
// number_of_fragments is set to 0 but we have a multivalued field
if (field.numberOfFragments() == 0 && textsToHighlight.size() > 1) {
if (field.numberOfFragments() == 0 && textsToHighlight.size() > 1 && fragsList.size() > 0) {
fragments = new String[1];
for (int i = 0; i < fragsList.size(); i++) {
fragments[0] = (fragments[0] != null ? (fragments[0] + " ") : "") + fragsList.get(i).toString();
@ -185,7 +185,7 @@ public class HighlightPhase implements SearchHitPhase {
}
}
if (fragments.length > 0) {
if (fragments != null && fragments.length > 0) {
HighlightField highlightField = new HighlightField(field.field(), fragments);
highlightFields.put(highlightField.name(), highlightField);
}