commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1716226 - in /commons/proper/jxpath/trunk/src: changes/changes.xml main/java/org/apache/commons/jxpath/ri/axes/ChildContext.java test/java/org/apache/commons/jxpath/issues/JXPath113Test.java
Date Tue, 24 Nov 2015 18:16:00 GMT
Author: britter
Date: Tue Nov 24 18:16:00 2015
New Revision: 1716226

URL: http://svn.apache.org/viewvc?rev=1716226&view=rev
Log:
JXPATH-113: NullPointerException in ChildContext when document only contains an empty root
node. Thanks to Michele Vivoda. This also fixes #1 from github.

Added:
    commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java
Modified:
    commons/proper/jxpath/trunk/src/changes/changes.xml
    commons/proper/jxpath/trunk/src/main/java/org/apache/commons/jxpath/ri/axes/ChildContext.java

Modified: commons/proper/jxpath/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/changes/changes.xml?rev=1716226&r1=1716225&r2=1716226&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/changes/changes.xml (original)
+++ commons/proper/jxpath/trunk/src/changes/changes.xml Tue Nov 24 18:16:00 2015
@@ -47,6 +47,9 @@ The <action> type attribute can be add,u
   <body>
     <!-- The release date is the date RC is cut -->
     <release version="1.4" date="2014-??-??" description="New features and bug fixes.">
+      <action issue="JXPATH-113" dev="britter" type="fix" due-to="Michele Vivoda">
+        NullPointerException in ChildContext when document only contains an empty root node
+      </action>
       <action issue="JXPATH-160" dev="britter" type="fix" due-to="Stefan Albrecht, Michele
Vivoda, Uwe Barthel">
         ValueUtils.getValue throws exception with set and index above size
       </action>

Modified: commons/proper/jxpath/trunk/src/main/java/org/apache/commons/jxpath/ri/axes/ChildContext.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/main/java/org/apache/commons/jxpath/ri/axes/ChildContext.java?rev=1716226&r1=1716225&r2=1716226&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/main/java/org/apache/commons/jxpath/ri/axes/ChildContext.java
(original)
+++ commons/proper/jxpath/trunk/src/main/java/org/apache/commons/jxpath/ri/axes/ChildContext.java
Tue Nov 24 18:16:00 2015
@@ -110,7 +110,7 @@ public class ChildContext extends EvalCo
             return;
         }
         NodePointer useParent = startFromParentLocation ? parent.getParent() : parent;
-        iterator = useParent.childIterator(nodeTest, reverse,
+        iterator = useParent == null ? null : useParent.childIterator(nodeTest, reverse,
                 startFromParentLocation ? parent : null);
     }
 }

Added: commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java?rev=1716226&view=auto
==============================================================================
--- commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java
(added)
+++ commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java
Tue Nov 24 18:16:00 2015
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jxpath.issues;
+
+import java.io.StringReader;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.jxpath.JXPathTestCase;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+public class JXPath113Test extends JXPathTestCase
+{
+
+    public void testIssue113() throws Exception
+    {
+        Document doc = JAXP.getDocument("<xml/>");
+        JXPathContext context = JXPathContext.newContext(doc);
+        context.selectNodes("//following-sibling::node()");
+    }
+
+    static class JAXP
+    {
+
+        public static Document getDocument(String xml) throws Exception
+        {
+            return getDocument(new InputSource(new StringReader(xml)));
+        }
+
+        public static Document getDocument(InputSource is) throws Exception
+        {
+
+            final DocumentBuilder builder = getDocumentBuilder();
+            return builder.parse(is);
+        }
+
+        private static DocumentBuilder getDocumentBuilder()
+        {
+            try
+            {
+                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+                factory.setValidating(false);
+                factory.setNamespaceAware(true);
+                factory.setExpandEntityReferences(false);
+                return factory.newDocumentBuilder();
+            }
+            catch (ParserConfigurationException e)
+            {
+                throw new Error("JAXP config error:" + e.getMessage(), e);
+            }
+
+        }
+    }
+
+}



Mime
View raw message