From 0a9ff14d96714eacfd759447fa1cfa58a1e8f257 Mon Sep 17 00:00:00 2001 From: luccioman Date: Wed, 7 Sep 2016 10:03:48 +0200 Subject: [PATCH] Fixed NullPointerException case and added Javadoc --- .../solr/responsewriter/OpensearchResponseWriter.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/net/yacy/cora/federate/solr/responsewriter/OpensearchResponseWriter.java b/source/net/yacy/cora/federate/solr/responsewriter/OpensearchResponseWriter.java index d6f728ca3..7445cddf5 100644 --- a/source/net/yacy/cora/federate/solr/responsewriter/OpensearchResponseWriter.java +++ b/source/net/yacy/cora/federate/solr/responsewriter/OpensearchResponseWriter.java @@ -343,13 +343,20 @@ public class OpensearchResponseWriter implements QueryResponseWriter { return; } + /** + * @param snippets snippets list eventually empty + * @return the largest snippet containing at least a space character among the list, or null + */ public static String getLargestSnippet(LinkedHashSet snippets) { if (snippets == null || snippets.size() == 0) return null; String l = null; for (String s: snippets) { if ((l == null || s.length() > l.length()) && s.indexOf(' ') > 0) l = s; } - return l.replaceAll("\"", "'"); + if(l != null) { + l = l.replaceAll("\"", "'"); + } + return l; } public static void openTag(final Writer writer, final String tag) throws IOException {