You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "Dave Thompson (Jira)" <ji...@apache.org> on 2023/09/26 15:40:00 UTC

[jira] [Closed] (DAFFODIL-2839) Cast from xs:double/xs:float to xs:unsignedLong fails with ClassCastException error

     [ https://issues.apache.org/jira/browse/DAFFODIL-2839?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dave Thompson closed DAFFODIL-2839.
-----------------------------------

Verified the specified commit is included in the latest pull from the daffodil repository.

Verified, via review, changes identified in the commit comment were implemented. 

Verified the affected daffodil subproject sbt test suites executed successfully including the added test.

Rolled the commit back to the pre-fix commit and verified the the added test failed as specified.

> Cast from xs:double/xs:float to xs:unsignedLong fails with ClassCastException error
> -----------------------------------------------------------------------------------
>
>                 Key: DAFFODIL-2839
>                 URL: https://issues.apache.org/jira/browse/DAFFODIL-2839
>             Project: Daffodil
>          Issue Type: Bug
>          Components: Front End
>            Reporter: Steve Lawrence
>            Priority: Major
>             Fix For: 3.5.1
>
>
> The following schema parses a double and then has an expression to convert that double to an unsignedLong:
> {code:xml}
>   <element name="root">
>     <complexType>
>       <sequence>
>         <element name="double" type="xs:double" />
>         <element name="ulong" type="xs:unsignedLong" dfdl:inputValueCalc="{ xs:unsignedLong(../double) }" />
>       </sequence>
>     </complexType>
>   </element>
> {code}
> This fails with the exception:
> {code}
> rg.apache.daffodil.lib.exceptions.Abort: Invariant broken. Runtime.scala - Leaked exception: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
> java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
> 	at org.apache.daffodil.runtime1.infoset.DataValue$.getLong$extension(DataValue.scala:91)
> 	at org.apache.daffodil.runtime1.dpath.LongToUnsignedLong$.computeValue(ConverterOps.scala:219)
> 	at org.apache.daffodil.runtime1.dpath.LongToUnsignedLong$.computeValue(ConverterOps.scala:217)
> 	at org.apache.daffodil.runtime1.dpath.Converter.run(DPathRuntime.scala:311)
> 	at org.apache.daffodil.runtime1.dpath.CompiledDPath.run(DPathRuntime.scala:148)
> 	at org.apache.daffodil.runtime1.dpath.CompiledDPath.runExpression(DPathRuntime.scala:73)
> 	at org.apache.daffodil.runtime1.dpath.RuntimeExpressionDPath.evaluateExpression(DPath.scala:283)
> 	at org.apache.daffodil.runtime1.dpath.RuntimeExpressionDPath.evaluateMaybe(DPath.scala:294)
> 	at org.apache.daffodil.runtime1.dpath.RuntimeExpressionDPath.evaluate(DPath.scala:307)
> {code}
> It seems like our expression compiler first converts the double to a long and then converts the long to an unsigned long, failing with the latter. Note that this is probably incorrect, since converting from a double to long first will limit the value to maxLong which it should not do.
> A sortof workaround is to change the expression to this:
> {code}
> xs:unsignedLong(xs:long(../double))
> {code}
> So we explicitly cast the double to a long, and then cast the long to the unsigned long. This still limits the range to maxLong, but does allow the conversion to succeed as expected as long as the double is in the range of 0 to maxLong.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)