From 7de9508aa52de62f0dc41e88c25096722d84a3b3 Mon Sep 17 00:00:00 2001 From: Tommaso Teofili Date: Thu, 7 Jun 2012 22:00:47 +0000 Subject: [PATCH] [SOLR-3221] - fixed possible NPE for text variable being null in UIMAUpdateRequestProcessor git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1347817 13f79535-47bb-0310-9956-ffa450edef68 --- .../processor/UIMAUpdateRequestProcessor.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/solr/contrib/uima/src/java/org/apache/solr/uima/processor/UIMAUpdateRequestProcessor.java b/solr/contrib/uima/src/java/org/apache/solr/uima/processor/UIMAUpdateRequestProcessor.java index 98c7f55d786..bbf601765bc 100644 --- a/solr/contrib/uima/src/java/org/apache/solr/uima/processor/UIMAUpdateRequestProcessor.java +++ b/solr/contrib/uima/src/java/org/apache/solr/uima/processor/UIMAUpdateRequestProcessor.java @@ -40,7 +40,6 @@ import java.util.Map; /** * Update document(s) to be indexed with UIMA extracted information * - * */ public class UIMAUpdateRequestProcessor extends UpdateRequestProcessor { @@ -102,16 +101,24 @@ public class UIMAUpdateRequestProcessor extends UpdateRequestProcessor { new StringBuilder(". ").append(logField).append("=") .append((String)cmd.getSolrInputDocument().getField(logField).getValue()) .append(", ").toString(); - int len = Math.min(text.length(), 100); + int len; + String debugString; + if (text != null && text.length() > 0) { + len = Math.min(text.length(), 100); + debugString = new StringBuilder(" text=\"").append(text.substring(0, len)).append("...\"").toString(); + } + else { + debugString = " null text"; + } if (solrUIMAConfiguration.isIgnoreErrors()) { log.warn(new StringBuilder("skip the text processing due to ") .append(e.getLocalizedMessage()).append(optionalFieldInfo) - .append(" text=\"").append(text.substring(0, len)).append("...\"").toString()); + .append(debugString).toString()); } else { throw new SolrException(ErrorCode.SERVER_ERROR, - new StringBuilder("processing error: ") + new StringBuilder("processing error ") .append(e.getLocalizedMessage()).append(optionalFieldInfo) - .append(" text=\"").append(text.substring(0, len)).append("...\"").toString(), e); + .append(debugString).toString(), e); } } super.processAdd(cmd);