Project

Profile

Help

Bug #4123

closed

ClassCastException running analyze-string after exporting/reloading and generating bytecode

Added by Michael Kay over 5 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
XSLT export
Sprint/Milestone:
-
Start date:
2019-01-30
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
9.9, trunk
Fix Committed on Branch:
9.9, trunk
Fixed in Maintenance Release:
Platforms:

Description

T. Hatanaka reported by direct email:

With the attached files, you can export and run test.xsl on Saxon-EE 9.9.0.2:


   C:\test>java -jar SaxonEE9-9-0-2J\saxon9ee.jar -export:test.sef -nogo -t -xsl:test.xsl
   Saxon-EE 9.9.0.2J from Saxonica
   Java version 1.8.0_181
   Using license serial number V006911
   URIResolver.resolve href="xhtml1-transitional.xsd" base="file:/C:/test/test.xsl"
   Loading schema document file:/C:/test/xhtml1-transitional.xsd
   URIResolver.resolve href="http://www.w3.org/2001/xml.xsd" base="file:/C:/test/xhtml1-transitional.xsd"
   Finished loading schema document file:/C:/test/xhtml1-transitional.xsd
   Stylesheet compilation time: 2.6360504s (2636.0504ms)
   Stylesheet exported to: C:\test\test.sef

   C:\test>java -jar SaxonEE9-9-0-2J\saxon9ee.jar -config:config.xml -s:test.xml -t -xsl:test.sef
   Saxon-EE 9.9.0.2J from Saxonica
   Java version 1.8.0_181
   Using license serial number V006911
   Stylesheet compilation time: 565.9796ms
   Processing file:/C:/test/test.xml
   Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
   Building tree for file:/C:/test/test.xml using class net.sf.saxon.tree.tiny.TinyBuilder
   Tree built in 19.1438ms
   Tree size: 766 nodes, 1760 characters, 0 attributes
   <?xml version="1.0" encoding="UTF-8"?>Lorem Lorem ...Execution time: 156.3841ms
   Memory used: 20,531,616


Doing the exact same commands fails on 9.9.1.1:

   C:\test>java -jar SaxonEE9-9-1-1J\saxon9ee.jar -export:test.sef -nogo -t -xsl:test.xsl
   Saxon-EE 9.9.1.1J from Saxonica
   Java version 1.8.0_181
   Using license serial number V006911
   URIResolver.resolve href="xhtml1-transitional.xsd" base="file:/C:/test/test.xsl"
   Loading schema document file:/C:/test/xhtml1-transitional.xsd
   URIResolver.resolve href="http://www.w3.org/2001/xml.xsd" base="file:/C:/test/xhtml1-transitional.xsd"
   Finished loading schema document file:/C:/test/xhtml1-transitional.xsd
   Stylesheet compilation time: 2.5840584s (2584.0584ms)
   Stylesheet exported to: C:\test\test.sef

   C:\test>java -jar SaxonEE9-9-1-1J\saxon9ee.jar -config:config.xml -s:test.xml -t -xsl:test.sef
   Saxon-EE 9.9.1.1J from Saxonica
   Java version 1.8.0_181
   Using license serial number V006911
   Stylesheet compilation time: 574.3212ms
   Processing file:/C:/test/test.xml
   Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
   Building tree for file:/C:/test/test.xml using class net.sf.saxon.tree.tiny.TinyBuilder
   Tree built in 17.9948ms
   Tree size: 766 nodes, 1760 characters, 0 attributes
   java.lang.ClassCastException: net.sf.saxon.value.StringValue cannot be cast to net.sf.saxon.om.NodeInfo
           at EE_EE_NonMatchingExpr_72005028997.iterate(file:/C:/test/test.xsl:19)
           at com.saxonica.ee.bytecode.CompiledExpression.iterate(CompiledExpression.java:210)
           at net.sf.saxon.expr.AnalyzeMappingFunction.map(AnalyzeMappingFunction.java:54)
           at net.sf.saxon.expr.ContextMappingIterator.next(ContextMappingIterator.java:62)
           at net.sf.saxon.tree.iter.AtomizingIterator.next(AtomizingIterator.java:59)
           at net.sf.saxon.tree.iter.AtomizingIterator.next(AtomizingIterator.java:27)
           at net.sf.saxon.expr.ItemMappingIterator.next(ItemMappingIterator.java:107)
           at net.sf.saxon.expr.CardinalityCheckingIterator.<init>(CardinalityCheckingIterator.java:48)
           at EE_treatAs_01810261598.process(file:/C:/test/test.xsl:19)
           at com.saxonica.ee.bytecode.CompiledExpression.process(CompiledExpression.java:84)
           at com.saxonica.ee.bytecode.ByteCodeCandidate.process(ByteCodeCandidate.java:143)
           at com.saxonica.ee.bytecode.ByteCodeCandidate.processLeavingTail(ByteCodeCandidate.java:188)
           at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:352)
           at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:519)
           at net.sf.saxon.expr.instruct.ApplyTemplates$ApplyTemplatesPackage.processLeavingTail(ApplyTemplates.java:557)
           at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:438)
           at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:733)
           at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:347)
           at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:311)
           at net.sf.saxon.Transform.processFile(Transform.java:1276)
           at net.sf.saxon.Transform.doTransform(Transform.java:804)
           at net.sf.saxon.Transform.main(Transform.java:80)
   java.lang.RuntimeException: Internal error evaluating template rule  at line 19 in module file:/C:/test/test.xsl
           at com.saxonica.ee.bytecode.ByteCodeCandidate.process(ByteCodeCandidate.java:156)
           at com.saxonica.ee.bytecode.ByteCodeCandidate.processLeavingTail(ByteCodeCandidate.java:188)
           at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:352)
           at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:519)
           at net.sf.saxon.expr.instruct.ApplyTemplates$ApplyTemplatesPackage.processLeavingTail(ApplyTemplates.java:557)
           at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:438)
           at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:733)
           at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:347)
           at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:311)
           at net.sf.saxon.Transform.processFile(Transform.java:1276)
           at net.sf.saxon.Transform.doTransform(Transform.java:804)
           at net.sf.saxon.Transform.main(Transform.java:80)
   Caused by: java.lang.ClassCastException: net.sf.saxon.value.StringValue cannot be cast to net.sf.saxon.om.NodeInfo
           at EE_EE_NonMatchingExpr_72005028997.iterate(file:/C:/test/test.xsl:19)
           at com.saxonica.ee.bytecode.CompiledExpression.iterate(CompiledExpression.java:210)
           at net.sf.saxon.expr.AnalyzeMappingFunction.map(AnalyzeMappingFunction.java:54)
           at net.sf.saxon.expr.ContextMappingIterator.next(ContextMappingIterator.java:62)
           at net.sf.saxon.tree.iter.AtomizingIterator.next(AtomizingIterator.java:59)
           at net.sf.saxon.tree.iter.AtomizingIterator.next(AtomizingIterator.java:27)
           at net.sf.saxon.expr.ItemMappingIterator.next(ItemMappingIterator.java:107)
           at net.sf.saxon.expr.CardinalityCheckingIterator.<init>(CardinalityCheckingIterator.java:48)
           at EE_treatAs_01810261598.process(file:/C:/test/test.xsl:19)
           at com.saxonica.ee.bytecode.CompiledExpression.process(CompiledExpression.java:84)
           at com.saxonica.ee.bytecode.ByteCodeCandidate.process(ByteCodeCandidate.java:143)
           ... 11 more
   java.lang.RuntimeException: Internal error evaluating template rule
           at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:371)
           at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:519)
           at net.sf.saxon.expr.instruct.ApplyTemplates$ApplyTemplatesPackage.processLeavingTail(ApplyTemplates.java:557)
           at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:438)
           at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:733)
           at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:347)
           at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:311)
           at net.sf.saxon.Transform.processFile(Transform.java:1276)
           at net.sf.saxon.Transform.doTransform(Transform.java:804)
           at net.sf.saxon.Transform.main(Transform.java:80)
   Caused by: java.lang.RuntimeException: Internal error evaluating template rule  at line 19 in module file:/C:/test/test.xsl
           at com.saxonica.ee.bytecode.ByteCodeCandidate.process(ByteCodeCandidate.java:156)
           at com.saxonica.ee.bytecode.ByteCodeCandidate.processLeavingTail(ByteCodeCandidate.java:188)
           at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:352)
           ... 9 more
   Caused by: java.lang.ClassCastException: net.sf.saxon.value.StringValue cannot be cast to net.sf.saxon.om.NodeInfo
           at EE_EE_NonMatchingExpr_72005028997.iterate(file:/C:/test/test.xsl:19)
           at com.saxonica.ee.bytecode.CompiledExpression.iterate(CompiledExpression.java:210)
           at net.sf.saxon.expr.AnalyzeMappingFunction.map(AnalyzeMappingFunction.java:54)
           at net.sf.saxon.expr.ContextMappingIterator.next(ContextMappingIterator.java:62)
           at net.sf.saxon.tree.iter.AtomizingIterator.next(AtomizingIterator.java:59)
           at net.sf.saxon.tree.iter.AtomizingIterator.next(AtomizingIterator.java:27)
           at net.sf.saxon.expr.ItemMappingIterator.next(ItemMappingIterator.java:107)
           at net.sf.saxon.expr.CardinalityCheckingIterator.<init>(CardinalityCheckingIterator.java:48)
           at EE_treatAs_01810261598.process(file:/C:/test/test.xsl:19)
           at com.saxonica.ee.bytecode.CompiledExpression.process(CompiledExpression.java:84)
           at com.saxonica.ee.bytecode.ByteCodeCandidate.process(ByteCodeCandidate.java:143)
           ... 11 more
   Fatal error during transformation: java.lang.RuntimeException: Internal error evaluating template rule


Actions #1

Updated by Michael Kay over 5 years ago

The bytecode generated from the reloaded SEF file is incorrect because the type information on the expression tree is incorrect (it thinks that the return type of xsl:copy will be node().)

This points up a general issue which is that the SEF file is not retaining very much type information, on the theory that it isn't needed at run-time. But bytecode generation makes extensive use of type information for efficient code generation.

Of course the particular problem here is that the type information is incorrect. But even if we fix it, the bytecode for xsl:copy is going to be inefficient unless the type information is not only correct, but precise.

We've been doing a lot of work recently on a new compiler for use under Node.js, and that compiler saves extensive type information into the SEF tree. We've also devised a compact representation of SequenceTypes suitable for export and reloading. Perhaps we should bite the bullet and bring this into the Java compiler too -- most of the groundwork has already been done.

Actions #2

Updated by Michael Kay over 5 years ago

The immediate problem is incorrect type inferencing for xsl:copy - with a schema-aware stylesheet this takes into account that the result type may differ from the input type because of validation, but it then wrongly concludes that if there is no validation, the result type will be node().

We can fix the immediate problem by changing Copy.computeItemType() so that if the input type overlaps with atomic or function, the result type is the same as the input type, even in the schema-aware case.

Actions #3

Updated by Michael Kay over 5 years ago

  • Status changed from New to Resolved
  • Fix Committed on Branch 9.9, trunk added

I've done some work to integrate the new type representations developed for node.js and use them in export files on the development branch, but I'm not going to transfer that to 9.9 for the time being; I'll just leave it that the type inference for Copy after an import is correct, and the bytecode therefore works, even though the type isn't very precise.

Actions #4

Updated by O'Neil Delpratt about 5 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 9.9.1.2 added

Bug issue fixed in the Saxon 9.9.1.2 maintenance release.

Please register to edit this issue

Also available in: Atom PDF