Apache Solr open-source search software
SOLR-1635: Fixed error message when numeric values can't be parsed by DOMUtils
Chris M. Hostetter8bbf9488b768
diff --git a/CHANGES.txt b/CHANGES.txtindex e857e639b01..2b2cf749e86 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -117,6 +117,9 @@ Bug Fixesin a multivalued field when term positions (term vectors) are stored.(Chris Harris via yonik)+* SOLR-1635: Fixed error message when numeric values can't be parsed by+ DOMUtils - notably for plugin init params in solrconfig.xml.+ (hossman)Other Changes----------------------diff --git a/src/common/org/apache/solr/common/util/DOMUtil.java b/src/common/org/apache/solr/common/util/DOMUtil.javaindex 797860bd619..d02be759bbd 100644--- a/src/common/org/apache/solr/common/util/DOMUtil.java+++ b/src/common/org/apache/solr/common/util/DOMUtil.java@@ -108,40 +108,60 @@ public class DOMUtil {return lst;}-+ /**+ * Examines a Node from the DOM representation of a NamedList and adds the+ * contents of that node to both the specified NamedList and List passed+ * as arguments.+ *+ * @param nd The Node whose type will be used to determine how to parse the+ * text content. If there is a 'name' attribute it will be used+ * when adding to the NamedList+ * @param nlst A NamedList to add the item to with name if application.+ * If this param is null it will be ignored.+ * @param arr A List to add the item to.+ * If this param is null it will be ignored.+ */@SuppressWarnings("unchecked")public static void addToNamedList(Node nd, NamedList nlst, List arr) {// Nodes often include whitespace, etc... so just return if this// is not an Element.if (nd.getNodeType() != Node.ELEMENT_NODE) return;- String type = nd.getNodeName();+ final String type = nd.getNodeName();- String name = null;- if (nd.hasAttributes()) {- NamedNodeMap attrs = nd.getAttributes();- Node nameNd = attrs.getNamedItem("name");- if (nameNd != null) name=nameNd.getNodeValue();- }+ final String name = getAttr(nd, "name");Object val=null;- if ("str".equals(type)) {- val = getText(nd);- } else if ("int".equals(type)) {- val = Integer.valueOf(getText(nd));- } else if ("long".equals(type)) {- val = Long.valueOf(getText(nd));- } else if ("float".equals(type)) {- val = Float.valueOf(getText(nd));- } else if ("double".equals(type)) {- val = Double.valueOf(getText(nd));- } else if ("bool".equals(type)) {- val = StrUtils.parseBool(getText(nd));- } else if ("lst".equals(type)) {+ if ("lst".equals(type)) {val = childNodesToNamedList(nd);} else if ("arr".equals(type)) {val = childNodesToList(nd);+ } else {+ final String textValue = getText(nd);+ try {+ if ("str".equals(type)) {+ val = textValue;+ } else if ("int".equals(type)) {+ val = Integer.valueOf(textValue);+ } else if ("long".equals(type)) {+ val = Long.valueOf(textValue);+ } else if ("float".equals(type)) {+ val = Float.valueOf(textValue);+ } else if ("double".equals(type)) {+ val = Double.valueOf(textValue);+ } else if ("bool".equals(type)) {+ val = StrUtils.parseBool(textValue);+ }+ // :NOTE: Unexpected Node names are ignored+ // :TODO: should we generate an error here?+ } catch (NumberFormatException nfe) {+ throw new SolrException+ (SolrException.ErrorCode.SERVER_ERROR,+ "Value " + (null != name ? ("of '" +name+ "' ") : "") ++ "can not be parsed as '" +type+ "': \"" + textValue + "\"",+ nfe);+ }}if (nlst != null) nlst.add(name,val);