You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2002/11/27 00:20:17 UTC

DO NOT REPLY [Bug 14875] New: - NullPointerException in XPath API

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14875>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14875

NullPointerException in XPath API

           Summary: NullPointerException in XPath API
           Product: XalanJ2
           Version: CurrentCVS
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: org.apache.xpath
        AssignedTo: xalan-dev@xml.apache.org
        ReportedBy: jonathan.spaeth@networktelephone.net


Overview Description:
I am developing a Xalan extension as a java class to react to elements of the 
syntax: <data:for-each select="xpath-expression"><element><data:value-of 
select="xpath-expression"></element></data:for-each> in a similar fashion to 
the <xsl:for-each> and <xsl:value-of> elements.  The xpath expressions provided 
in the select attributes will be evaluated against the same document from which 
the tags were embedded.

Every call I have made to the XPathAPI class, however, has resulted in a 
NullPointerException being thrown.  I have tracked the generation of the 
exception to the following method: org.apache.xpath.axes.AxesWalker.setRoot
(int).
Within this method, the offending lines of code are:

public void setRoot(int root) {
 XPathContext xctxt = wi().getXPathContext();
 m_dtm = xctxt.getDTM(root);
 m_traverser = m_dtm.getAxisTraverser(m_axis);
 ...
}
It seems that the XPathContext returns a null dtm.

I have attempted running this with multiple types of xpath queries in my 
example each time with the same results, the only difference being the concrete 
type of axis class from which the exception is generated.

Steps to Reproduce:
1. Compile my xalan extension: DataMixer.java (included at the end of this bug).
2. Start the xalan processor with the following command line:
java -Xbootclasspath/p:"<path-to-xalan.jar>;<path-to-xercesImpl.jar>;<path-to-
xml-apis.jar>" -cp "<path-to-DataMixer.class>" org.apache.xalan.xslt.Process -
in test.xml -out test.html -xsl test.xslt

Actual Results:
This is the stack dump of the exception that was thrown:

javax.xml.transform.TransformerException: Unknown error in XPath
        at org.apache.xpath.XPath.execute(XPath.java:336)
        at org.apache.xpath.XPathAPI.eval(XPathAPI.java:285)
        at org.apache.xpath.XPathAPI.selectNodeList(XPathAPI.java:211)
        at org.apache.xpath.XPathAPI.selectNodeList(XPathAPI.java:191)
        at com.networktel.jon.xalanext.DataMixer.forEach(DataMixer.java:27)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at org.apache.xalan.extensions.ExtensionHandlerJavaClass.processElement
(ExtensionHandlerJavaClass.java:449)
        at org.apache.xalan.templates.ElemExtensionCall.execute
(ElemExtensionCall.java:283)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes
(ElemApplyTemplates.java:425)
        at org.apache.xalan.templates.ElemApplyTemplates.execute
(ElemApplyTemplates.java:216)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2347)
        at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:162)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes
(ElemApplyTemplates.java:425)
        at org.apache.xalan.templates.ElemApplyTemplates.execute
(ElemApplyTemplates.java:216)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2347)
        at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:162)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes
(ElemApplyTemplates.java:425)
        at org.apache.xalan.templates.ElemApplyTemplates.execute
(ElemApplyTemplates.java:216)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2347)
        at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:162)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes
(ElemApplyTemplates.java:425)
        at org.apache.xalan.templates.ElemApplyTemplates.execute
(ElemApplyTemplates.java:216)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2347)
        at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:162)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes
(ElemApplyTemplates.java:425)
        at org.apache.xalan.templates.ElemApplyTemplates.execute
(ElemApplyTemplates.java:216)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2347)
        at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:162)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes
(ElemApplyTemplates.java:425)
        at org.apache.xalan.templates.ElemApplyTemplates.execute
(ElemApplyTemplates.java:216)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2347)
        at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode
(TransformerImpl.java:2168)
        at org.apache.xalan.transformer.TransformerImpl.transformNode
(TransformerImpl.java:1221)
        at org.apache.xalan.transformer.TransformerImpl.transform
(TransformerImpl.java:676)
        at org.apache.xalan.transformer.TransformerImpl.transform
(TransformerImpl.java:1137)
        at org.apache.xalan.transformer.TransformerImpl.transform
(TransformerImpl.java:1115)
        at org.apache.xalan.xslt.Process.main(Process.java:1041)
Caused by: java.lang.NullPointerException
        at org.apache.xpath.axes.AxesWalker.setRoot(AxesWalker.java:258)
        at org.apache.xpath.axes.WalkingIterator.setRoot
(WalkingIterator.java:138)
        at org.apache.xpath.axes.NodeSequence.setRoot(NodeSequence.java:253)
        at org.apache.xpath.axes.LocPathIterator.execute
(LocPathIterator.java:257)
        at org.apache.xpath.XPath.execute(XPath.java:308)
        ... 39 more
---------
java.lang.NullPointerException
        at org.apache.xpath.axes.AxesWalker.setRoot(AxesWalker.java:258)
        at org.apache.xpath.axes.WalkingIterator.setRoot
(WalkingIterator.java:138)
        at org.apache.xpath.axes.NodeSequence.setRoot(NodeSequence.java:253)
        at org.apache.xpath.axes.LocPathIterator.execute
(LocPathIterator.java:257)
        at org.apache.xpath.XPath.execute(XPath.java:308)
        at org.apache.xpath.XPathAPI.eval(XPathAPI.java:285)
        at org.apache.xpath.XPathAPI.selectNodeList(XPathAPI.java:211)
        at org.apache.xpath.XPathAPI.selectNodeList(XPathAPI.java:191)
        at com.networktel.jon.xalanext.DataMixer.forEach(DataMixer.java:27)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at org.apache.xalan.extensions.ExtensionHandlerJavaClass.processElement
(ExtensionHandlerJavaClass.java:449)
        at org.apache.xalan.templates.ElemExtensionCall.execute
(ElemExtensionCall.java:283)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes
(ElemApplyTemplates.java:425)
        at org.apache.xalan.templates.ElemApplyTemplates.execute
(ElemApplyTemplates.java:216)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2347)
        at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:162)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes
(ElemApplyTemplates.java:425)
        at org.apache.xalan.templates.ElemApplyTemplates.execute
(ElemApplyTemplates.java:216)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2347)
        at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:162)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes
(ElemApplyTemplates.java:425)
        at org.apache.xalan.templates.ElemApplyTemplates.execute
(ElemApplyTemplates.java:216)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2347)
        at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:162)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes
(ElemApplyTemplates.java:425)
        at org.apache.xalan.templates.ElemApplyTemplates.execute
(ElemApplyTemplates.java:216)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2347)
        at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:162)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes
(ElemApplyTemplates.java:425)
        at org.apache.xalan.templates.ElemApplyTemplates.execute
(ElemApplyTemplates.java:216)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2347)
        at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:162)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes
(ElemApplyTemplates.java:425)
        at org.apache.xalan.templates.ElemApplyTemplates.execute
(ElemApplyTemplates.java:216)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2347)
        at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode
(TransformerImpl.java:2168)
        at org.apache.xalan.transformer.TransformerImpl.transformNode
(TransformerImpl.java:1221)
        at org.apache.xalan.transformer.TransformerImpl.transform
(TransformerImpl.java:676)
        at org.apache.xalan.transformer.TransformerImpl.transform
(TransformerImpl.java:1137)
        at org.apache.xalan.transformer.TransformerImpl.transform
(TransformerImpl.java:1115)
        at org.apache.xalan.xslt.Process.main(Process.java:1041)

Expected Results:
A successful transformation.

Build Date and Platform:
xalan-j_20021126 build on Windows 2000

Additional Builds and Platforms:
jdk 1.4.1_01

Additional Information:

test.xml:
<?xml version="1.0"?>
<myFile xmlns:data="http://networktel.net/data">
	<networkdb>
		<module id="atm.provisioning">
			<region id="north">
				<atm-switch id="switch1"/>
				<atm-switch id="switch2"/>
			</region>
			<region id="south">
				<atm-switch id="switch3"/>
				<atm-switch id="switch4"/>
			</region>
		</module>
	</networkdb>
	<modulePage>
		<form id="atm.provision">
			<selectOne ref="/region">
				<caption>Please select a region:</caption>
				<choices>
				<data:for-each select="//networkdb/module
[@id='atm.provisioning']"><testme></data:for-each>
				</choices>
			</selectOne>
			<submit>
				<caption>Submit</caption>
			</submit>
			<reset>
				<caption>Clear</caption>
			</reset>
		</form>
	</modulePage>
</myFile>

test.xslt:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:lxslt="http://xml.apache.org/xslt" 
	xmlns:data="http://networktel.net/data" 
	xmlns:mixer="xalan://com.networktel.jon.xalanext.DataMixer" 
	extension-element-prefixes="mixer">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	
	<xsl:template match="data:for-each">
		<mixer:forEach/>
	</xsl:template>
	<xsl:template match="data:value-of">
		<mixer:valueOf/>
	</xsl:template>

	<!-- match the default node -->
	<xsl:template match="*">
		<xsl:copy>
			<xsl:copy-of select="@*"/>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>

com.networktel.jon.xalanext.DataMixer.java:
package com.networktel.jon.xalanext;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.NamedNodeMap;
import org.apache.xpath.XPathAPI;
public class DataMixer {
	public java.util.Hashtable cache;
/**
 * 
 * @return org.w3c.dom.Node
 * @param context org.apache.xalan.extensions.XSLProcessorContext
 * @param extElement org.apache.xalan.templates.ElemExtensionCall
 */
public org.w3c.dom.Node forEach(org.apache.xalan.extensions.XSLProcessorContext 
context, org.apache.xalan.templates.ElemExtensionCall extElement) {
	NodeList xpathNodes;
	Node curNode, outputNode;
	String xpathQuery;
	int iLen, i, jLen, j;

	// get the query
	xpathQuery = this.getContextAttribute(context.getContextNode
(), "select");

	// execute the query
	try
	{
		xpathNodes = XPathAPI.selectNodeList(context.getContextNode(), 
xpathQuery);
	}
	catch (javax.xml.transform.TransformerException e)
	{
		e.printStackTrace();
		return null;
	}

	// create the output node
	outputNode = extElement.createElement("myElement");

	// iterate over the resulting nodes
	for (i=0, iLen=xpathNodes.getLength(); i<iLen; i++)
	{
		curNode = xpathNodes.item(i);
		outputNode.appendChild(extElement.createElement
(curNode.getNodeName()));
	}

	return outputNode;
}
/**
 * 
 * @return java.lang.String
 * @param context org.w3c.dom.Node
 * @param attr java.lang.String
 */
protected String getContextAttribute(Node context, String attr) {
	NamedNodeMap attributes = context.getAttributes();
	Node attrNode = attributes.getNamedItem(attr);

	if (attrNode == null)
		return "";
	else
		return attrNode.getNodeValue();
}
/**
 * 
 * @return java.lang.String
 * @param context org.apache.xalan.extensions.XSLProcessorContext
 * @param extElement org.apache.xalan.templates.ElemExtensionCall
 */
public String valueOf(org.apache.xalan.extensions.XSLProcessorContext context, 
org.apache.xalan.templates.ElemExtensionCall extElement) {
	return "hi";
}
}