Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E532B18A71 for ; Tue, 24 Nov 2015 19:34:08 +0000 (UTC) Received: (qmail 22974 invoked by uid 500); 24 Nov 2015 19:34:08 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 22901 invoked by uid 500); 24 Nov 2015 19:34:08 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 22892 invoked by uid 99); 24 Nov 2015 19:34:08 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Nov 2015 19:34:08 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 49662180992 for ; Tue, 24 Nov 2015 19:34:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.246 X-Spam-Level: * X-Spam-Status: No, score=1.246 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.554] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id wuH_OoEXvMSD for ; Tue, 24 Nov 2015 19:34:07 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTP id ED28442ACE for ; Tue, 24 Nov 2015 19:34:06 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 6D226E0FF9 for ; Tue, 24 Nov 2015 19:34:06 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id ED8323A242D for ; Tue, 24 Nov 2015 18:16:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: britter@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151124181600.ED8323A242D@svn01-us-west.apache.org> 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 type attribute can be add,u + + NullPointerException in ChildContext when document only contains an empty root node + ValueUtils.getValue throws exception with set and index above size 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(""); + 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); + } + + } + } + +}