Permalink
Browse files

Fix NPE in HighlightField serialization. Fixes #1380

  • Loading branch information...
1 parent 4bbe1b1 commit bd87f8de3ac84eb408d5ada0976664545c9228a0 @imotov imotov committed with kimchy Oct 7, 2011
View
6 modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java
@@ -169,9 +169,9 @@ public int compare(TextFragment o1, TextFragment o2) {
}
});
}
- 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 int compare(TextFragment o1, TextFragment o2) {
}
}
- if (fragments.length > 0) {
+ if (fragments != null && fragments.length > 0) {
HighlightField highlightField = new HighlightField(field.field(), fragments);
highlightFields.put(highlightField.name(), highlightField);
}

0 comments on commit bd87f8d

Please sign in to comment.