compile time java.lang.ClassCastException
Added by Anonymous over 15 years ago
Legacy ID: #7377295 Legacy Poster: Greg Knittl (gknittl)
Testcase: (errorstack.xsl) <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"> <xsl:template name="main"> <xsl:variable name="row" as="element()*"> <xsl:for-each-group select="'fred'" group-by="@cat"> <xsl:sort select='current-grouping-key()'/> </xsl:for-each-group> </xsl:variable> <xsl:sequence select="$row[@num eq '1']/xs:decimal(@amt)"/> </xsl:template> </xsl:stylesheet> Invocation: java net.sf.saxon.Transform -it main -t "errorstack.xsl" Output: Saxon 9.1.0.6J from Saxonica Java version 1.6.0_07 java.lang.ClassCastException: net.sf.saxon.expr.Literal cannot be cast to net.sf.saxon.expr.VariableReference at net.sf.saxon.expr.LetExpression.replaceVariable(LetExpression.java:517) at net.sf.saxon.expr.LetExpression.replaceVariable(LetExpression.java:514) at net.sf.saxon.expr.LetExpression.optimize(LetExpression.java:208) at net.sf.saxon.expr.ExpressionVisitor.optimize(ExpressionVisitor.java:200) at net.sf.saxon.style.XSLTemplate.compile(XSLTemplate.java:345) at net.sf.saxon.style.XSLStylesheet.compileStylesheet(XSLStylesheet.java:1089) at net.sf.saxon.PreparedStylesheet.setStylesheetDocument(PreparedStylesheet.java:346) at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:163) at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:139) at net.sf.saxon.Transform.doTransform(Transform.java:682) at net.sf.saxon.Transform.main(Transform.java:66) Fatal error during transformation: java.lang.ClassCastException: net.sf.saxon.expr.Literal cannot be cast to net.sf.saxon.expr.VariableReference
Replies (1)
RE: compile time java.lang.ClassCastException - Added by Anonymous over 15 years ago
Legacy ID: #7378104 Legacy Poster: Michael Kay (mhkay)
This is caused by two optimizations getting in the way of each other. The system has decided that the variable $row is eligible for indexing (although this doesn't actually happen except under Saxon-SA) because of the way it is used in a filter expression, and it has also discovered that the value of $row will always be an empty sequence, and in effect it falls over marking the empty sequence as being suitable for indexing. I will raise a patch in Subversion.
Please register to reply