Bug #3164
closedjava.lang.ClassCastException: net.sf.saxon.tree.tiny.TinyAttributeImpl cannot be cast to org.w3c.dom.Attr
100%
Description
While writing an extension function using Saxon PE 9.7.0.15 I get this ClassCastException.
public static Node foo(Document commandNode) {
Element command = commandNode.getDocumentElement();
System.out.println("xxx get start");
Attr attributeNode = command.getAttributeNode("width");
System.out.println("xxx get end");
I call the function from XSLT with:
<xsl:value-of select="mycompany:foo($pie)"/>
The output is:
xxx get start
net.sf.saxon.trans.XPathException: Exception thrown by extension function
{public static org.w3c.dom.Node com.mycompany.MyObject.foo(org.w3c.dom.Document)}:
java.lang.ClassCastException: net.sf.saxon.tree.tiny.TinyAttributeImpl cannot be cast to org.w3c.dom.Attr
Within the Saxon source code ElementOverNodeInfo.java method getAttriuteNode line 119 there is:
if (att.getDisplayName().equals(name)) {
return (Attr) att;
}
I think this is where the ClassCastException is occurring. (The stack backtrace does not show where the ClassCastException is occuring, it only shows from my method calling the XSLT processor back up to the main method.)
As far as I can see the TinyAttributeImpl class is supposed to be the Saxon implementation of the Attr interface for the purposes of converting documents to DOM structures when doing extension methods in Java. Yet TinyAttributeImpl does not implement Attr.
Please register to edit this issue