From bd87f8de3ac84eb408d5ada0976664545c9228a0 Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Fri, 7 Oct 2011 19:21:21 -0400 Subject: [PATCH] Fix NPE in HighlightField serialization. Fixes #1380 --- .../org/elasticsearch/search/highlight/HighlightPhase.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java index 5f80520aadf..44f32737026 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java @@ -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); }