Xpath NullPointerException in setNamespaceContext after calling reset

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Xpath NullPointerException in setNamespaceContext after calling reset

mlist.mr
Hi,

I use saxonb v8.6 with jdk 1.4.2 + jaxp 1.3.1

After calling reset on an Xpath (net.sf.saxon.xpath.XPathEvaluator)
object a call to setNamingContext throws a NullPointerException.

Here come an example of code producing this exception :
===============================================
/*
* setNameSpaceContextTest.java
*/
package org.microu.util.xml;

import java.util.Collections;
import java.util.Iterator;
import javax.xml.namespace.NamespaceContext;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;

import org.xml.sax.InputSource;

public class setNameSpaceContextTest {

    /**
     * @param args
     * @throws XPathExpressionException
     */
    public static void main(String[] args) throws XPathExpressionException {
        NamespaceContext namespaceContext= new EmptyNamespaceContext();
        String result;

        XPath xpath =
net.sf.saxon.xpath.XPathFactoryImpl.newInstance().newXPath();

        xpath.setNamespaceContext(namespaceContext);
        result = (String) xpath.evaluate("/document/title", new
InputSource("src/testdata/xml/test.xml"), XPathConstants.STRING);
        System.out.println("1 - RESULT : " + result);

        xpath.reset();
        // after the call to reset setNamespaceContext generate a
NullPointerException
        try {
            xpath.setNamespaceContext(namespaceContext);
        } catch (NullPointerException e) {
            e.printStackTrace();
        }




    }

    private static class EmptyNamespaceContext implements NamespaceContext {

        public String getNamespaceURI(String prefix) {
            return null;
        }

        public String getPrefix(String namespaceURI) {
            return null;
        }

        public Iterator getPrefixes(String namespaceURI) {
            return Collections.EMPTY_LIST.iterator();
        }

    }

}
=============================================

And the ouput of this program :
===================================================
1 - RESULT : TITLE
java.lang.NullPointerException
    at
net.sf.saxon.xpath.XPathEvaluator.setNamespaceContext(XPathEvaluator.java:281)
    at
org.microu.util.xml.setNameSpaceContextTest.main(setNameSpaceContextTest.java:35)
java.lang.NullPointerException
    at net.sf.saxon.expr.ExpressionParser.parse(ExpressionParser.java:189)
    at net.sf.saxon.expr.ExpressionTool.make(ExpressionTool.java:53)
    at
net.sf.saxon.xpath.XPathEvaluator.createExpression(XPathEvaluator.java:147)
    at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:316)
    at net.sf.saxon.xpath.XPathEvaluator.evaluate(XPathEvaluator.java:371)
    at
org.microu.util.xml.setNameSpaceContextTest.main(setNameSpaceContextTest.java:39)
Exception in thread "main"
================================================================

As far as I understand the jaxp XPATH API this use of reset() should
work ? It works with xalan 2.7.0.

Thanks for your help.

Michel Rousset






-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Xpath NullPointerException in setNamespaceContext after calling reset

Michael Kay
Thanks for reporting this. I've put a source fix at

https://sourceforge.net/tracker/index.php?func=detail&aid=1358908&group_id=2
9872&atid=397617

or as a circumvention, after calling reset(), do setStaticContext(new
StandaloneContext(config)).

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of mlist.mr
> Sent: 17 November 2005 04:08
> To: [hidden email]
> Subject: [saxon] Xpath NullPointerException in
> setNamespaceContext after calling reset
>
> Hi,
>
> I use saxonb v8.6 with jdk 1.4.2 + jaxp 1.3.1
>
> After calling reset on an Xpath (net.sf.saxon.xpath.XPathEvaluator)
> object a call to setNamingContext throws a NullPointerException.
>
> Here come an example of code producing this exception :
> ===============================================
> /*
> * setNameSpaceContextTest.java
> */
> package org.microu.util.xml;
>
> import java.util.Collections;
> import java.util.Iterator;
> import javax.xml.namespace.NamespaceContext;
> import javax.xml.xpath.XPath;
> import javax.xml.xpath.XPathConstants;
> import javax.xml.xpath.XPathExpressionException;
>
> import org.xml.sax.InputSource;
>
> public class setNameSpaceContextTest {
>
>     /**
>      * @param args
>      * @throws XPathExpressionException
>      */
>     public static void main(String[] args) throws
> XPathExpressionException {
>         NamespaceContext namespaceContext= new
> EmptyNamespaceContext();
>         String result;
>
>         XPath xpath =
> net.sf.saxon.xpath.XPathFactoryImpl.newInstance().newXPath();
>
>         xpath.setNamespaceContext(namespaceContext);
>         result = (String) xpath.evaluate("/document/title", new
> InputSource("src/testdata/xml/test.xml"), XPathConstants.STRING);
>         System.out.println("1 - RESULT : " + result);
>
>         xpath.reset();
>         // after the call to reset setNamespaceContext generate a
> NullPointerException
>         try {
>             xpath.setNamespaceContext(namespaceContext);
>         } catch (NullPointerException e) {
>             e.printStackTrace();
>         }
>
>
>
>
>     }
>
>     private static class EmptyNamespaceContext implements
> NamespaceContext {
>
>         public String getNamespaceURI(String prefix) {
>             return null;
>         }
>
>         public String getPrefix(String namespaceURI) {
>             return null;
>         }
>
>         public Iterator getPrefixes(String namespaceURI) {
>             return Collections.EMPTY_LIST.iterator();
>         }
>
>     }
>
> }
> =============================================
>
> And the ouput of this program :
> ===================================================
> 1 - RESULT : TITLE
> java.lang.NullPointerException
>     at
> net.sf.saxon.xpath.XPathEvaluator.setNamespaceContext(XPathEva
> luator.java:281)
>     at
> org.microu.util.xml.setNameSpaceContextTest.main(setNameSpaceC
> ontextTest.java:35)
> java.lang.NullPointerException
>     at
> net.sf.saxon.expr.ExpressionParser.parse(ExpressionParser.java:189)
>     at net.sf.saxon.expr.ExpressionTool.make(ExpressionTool.java:53)
>     at
> net.sf.saxon.xpath.XPathEvaluator.createExpression(XPathEvalua
> tor.java:147)
>     at
> net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:316)
>     at
> net.sf.saxon.xpath.XPathEvaluator.evaluate(XPathEvaluator.java:371)
>     at
> org.microu.util.xml.setNameSpaceContextTest.main(setNameSpaceC
> ontextTest.java:39)
> Exception in thread "main"
> ================================================================
>
> As far as I understand the jaxp XPATH API this use of reset() should
> work ? It works with xalan 2.7.0.
>
> Thanks for your help.
>
> Michel Rousset
>
>
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
> Register for a JBoss Training Course.  Free Certification Exam
> for All Training Attendees Through End of 2005. For more info visit:
> http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help