Project

Profile

Help

ClassCastException when calling "serialize" function with "map { html-version : 5 }"

Added by Martin Honnen almost 6 years ago

I have run into a quirk when using the @serialize@ function with serialization options where the @html-version@ is set to the integer @5@ e.g.


serialize(
  
    
      <title>Test</title>
    
    
      

This is a test.
This is a test.

, map { 'method' : 'html', 'indent' : true(), 'html-version' : 5 } )

gives a (tested with @Saxon-HE 9.8.0.12J@ from the command line) ClassCastException

java.lang.ClassCastException: net.sf.saxon.value.Int64Value cannot be cast to net.sf.saxon.value.BigDecimalValue
        at net.sf.saxon.functions.Serialize.setSerializationParams(Serialize.java:365)
        at net.sf.saxon.functions.Serialize.evalSerialize(Serialize.java:485)
        at net.sf.saxon.functions.Serialize.call(Serialize.java:441)
        at net.sf.saxon.functions.Serialize.call(Serialize.java:49)
        at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:547)
        at net.sf.saxon.expr.Expression.process(Expression.java:930)
        at net.sf.saxon.query.XQueryExpression.run(XQueryExpression.java:411)
        at net.sf.saxon.s9api.XQueryEvaluator.run(XQueryEvaluator.java:370)
        at net.sf.saxon.Query.runQuery(Query.java:955)
        at net.sf.saxon.Query.doQuery(Query.java:456)
        at net.sf.saxon.Query.main(Query.java:107)

Granted, the spec on @serialize@ declares the @html-version@ parameter as type @xs:decimal@ but as that spec also says

Subtype Substitution: A derived type may substitute for its base type. In particular, xs:integer may be used where xs:decimal is expected.

I would expect the integer @5@ to be accepted.


Replies (1)

RE: ClassCastException when calling "serialize" function with "map { html-version : 5 }" - Added by Michael Kay almost 6 years ago

Thanks. Logged as an issue here: https://saxonica.plan.io/issues/3781

There was some reorganization of the Java class hierarchy for decimals in 9.8. We now have:

AtomicValue
-- NumericValue
----DecimalValue
------IntegerValue
--------BigIntegerValue
--------Int64Value
------BigDecimalValue

whereas 9.7 had

AtomicValue
-- NumericValue
----DecimalValue
----IntegerValue
------BigIntegerValue
------Int64Value

The new structure more closely reflects the XPath type hierarchy so it should make this kind of problem easier to avoid, but there are probably a few cases like this where the change has not been followed through.

    (1-1/1)

    Please register to reply