From 14c977dd26b8810ecb12deab2dc23429cd269ffa Mon Sep 17 00:00:00 2001 From: reger Date: Tue, 31 Dec 2013 23:01:41 +0100 Subject: [PATCH] fix NPE GSAresponseWriter on query=null java.lang.NullPointerException at net.yacy.cora.federate.solr.responsewriter.GSAResponseWriter.highlight(GSAResponseWriter.java:328) at net.yacy.cora.federate.solr.responsewriter.GSAResponseWriter.write(GSAResponseWriter.java:263) at net.yacy.http.servlets.SolrServlet.service(SolrServlet.java:235) --- .../solr/responsewriter/GSAResponseWriter.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/source/net/yacy/cora/federate/solr/responsewriter/GSAResponseWriter.java b/source/net/yacy/cora/federate/solr/responsewriter/GSAResponseWriter.java index 7222bddac..6c1331b14 100644 --- a/source/net/yacy/cora/federate/solr/responsewriter/GSAResponseWriter.java +++ b/source/net/yacy/cora/federate/solr/responsewriter/GSAResponseWriter.java @@ -325,12 +325,15 @@ public class GSAResponseWriter implements QueryResponseWriter { } public static String highlight(String text, String query) { - String[] q = CommonPattern.SPACE.split(CommonPattern.PLUS.matcher(query.trim().toLowerCase()).replaceAll(" ")); - for (String s: q) { - int p = text.toLowerCase().indexOf(s.toLowerCase()); - if (p < 0) continue; - text = text.substring(0, p) + "" + text.substring(p, p + s.length()) + "" + text.substring(p + s.length()); - } - return text.replaceAll(Pattern.quote(" "), " "); + if (query != null) { + String[] q = CommonPattern.SPACE.split(CommonPattern.PLUS.matcher(query.trim().toLowerCase()).replaceAll(" ")); + for (String s: q) { + int p = text.toLowerCase().indexOf(s.toLowerCase()); + if (p < 0) continue; + text = text.substring(0, p) + "" + text.substring(p, p + s.length()) + "" + text.substring(p + s.length()); + } + return text.replaceAll(Pattern.quote(" "), " "); + } + return text; } } \ No newline at end of file