Project

Profile

Help

XQuery: 9.1 build ClassCastException

Added by Anonymous almost 16 years ago

Legacy ID: #5117173 Legacy Poster: Patrick Oosterveld (poosterveld)

We have a xquery with an expression assigned to a variable named; toegestaneLeeftijd. During Saxon evaluation it will throws a convert exception. Probably because its an expression rather than a simple value although the result of the expression will always be an integer. Is this a bug (in the previous releases this construction works fine)? A workaround is to 'type' cast toegestaneLeeftijd to a string (string($toegestaneLeeftijd)) and create new method in the Util class which can handle the string parameter. XQuery: let $toegestaneLeeftijd := if ($redenSignalering eq $rs1) then 12 else if ($redenSignalering eq $rs3) then 18 else if ($redenSignalering eq $rs4) then 18 else if ($redenSignalering eq $rs6) then 12 else if ($redenSignalering eq $rs7) then 12 else if ($redenSignalering eq $rs8) then 12 else if ($redenSignalering eq $rs9) then 12 else if ($redenSignalering eq $rs10) then 18 else if ($redenSignalering eq $rs11) then 18 else 0 let $dateToCheck := xs:date(util:addYearsToDate(string($geboortedatum), $toegestaneLeeftijd)) The util java class: public static final String addYearsToDate(Date d, int numberOfYearsToAdd) { GregorianCalendar c = new GregorianCalendar(); c.setTime(d); c.add(GregorianCalendar.YEAR, numberOfYearsToAdd); return formatToXSDate(c.getTime()); } The exception: at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Caused by: java.lang.ClassCastException: net.sf.saxon.value.SingletonClosure at net.sf.saxon.expr.PJConverter$IntegerValueToInt.convert(PJConverter.java:641) at net.sf.saxon.functions.ExtensionFunctionCall.setupParams(ExtensionFunctionCall.java:482) at net.sf.saxon.functions.ExtensionFunctionCall.call(ExtensionFunctionCall.java:336) at net.sf.saxon.functions.ExtensionFunctionCall.iterate(ExtensionFunctionCall.java:224) at net.sf.saxon.expr.Expression.evaluateItem(Expression.java:352)


Replies (5)

Please register to reply

RE: XQuery: 9.1 build ClassCastException - Added by Anonymous almost 16 years ago

Legacy ID: #5118034 Legacy Poster: Michael Kay (mhkay)

Yes, this looks like a bug - the particular code path isn't allowing for the fact that the supplied parameter value might be using lazy evaluation. I'll look into it. You can probably work around it by passing ($toegestaneLeeftijd + 0), or something similar, as the parameter value. I'm not actually sure WHY lazy evaluation is being used here: any chance you can send me a complete repro so I can see more precisely what is going on?

RE: XQuery: 9.1 build ClassCastException - Added by Anonymous almost 16 years ago

Legacy ID: #5120411 Legacy Poster: Patrick Oosterveld (poosterveld)

Yep I can send a repro (xml+xquery+util class). Do you have an email address for me? Or can I send it to mhkay at users.sourceforge.net?

RE: XQuery: 9.1 build ClassCastException - Added by Anonymous almost 16 years ago

Legacy ID: #5126481 Legacy Poster: Patrick Oosterveld (poosterveld)

A complete repro can be found in the support-requests tracker, see request number 2030045.

RE: XQuery: 9.1 build ClassCastException - Added by Anonymous almost 16 years ago

Legacy ID: #5127320 Legacy Poster: Michael Kay (mhkay)

You had me confused for a while here, because you posted the version of the query containing the workaround rather than the one that reveals the problem. But I worked out what was happening in the end, and have reproduced the problem, and I will publish a patch in due course. I was a bit puzzled at first that lazy evaluation should be used for the variable $toegestaneLeeftijd. It turns out this is done because it is evaluated outside the "for $x in //root/top[catid/code = 11] " loop, because it doesn't depend on anything in that loop. The other thing I noticed is that you are using a DOM tree as input to the query. You should be aware that this is MUCH slower than using Saxon's native tree implementation.

RE: XQuery: 9.1 build ClassCastException - Added by Anonymous over 15 years ago

Legacy ID: #5128154 Legacy Poster: Patrick Oosterveld (poosterveld)

  1. indeed I accidentally posted the wrong XQuery :-(. 2. Although the posted XQuery is a rewritten version, the original one had the same structure. You are right the expression could be placed outside the loop. 3. thanks. We implemented the tinytree for XSLT processing (see http://saxonica.blogharbor.com/blog/_archives/2007/3/31/2848654.html), but forgot to implement it for the XQueries. Thanks again.
    (1-5/5)

    Please register to reply