Project

Profile

Help

ClassCastException in ArithmeticExpression

Added by Anonymous over 18 years ago

Legacy ID: #3366019 Legacy Poster: marcvc (marcvc)

Michael, rather found by accident... Consider the following query: for $i in 1 return $i + doc("foo.xml")/element()[false()] With Saxon 8.5.1 this results in a ClassCastException: java.lang.ClassCastException at net.sf.saxon.expr.ArithmeticExpression.typeCheck(ArithmeticExpression.java:157) at net.sf.saxon.expr.ForExpression.typeCheck(ForExpression.java:102) at net.sf.saxon.expr.LetExpression.typeCheck(LetExpression.java:59) at net.sf.saxon.expr.ForExpression.extractLoopInvariants(ForExpression.java:219) at net.sf.saxon.expr.ForExpression.optimize(ForExpression.java:160) at net.sf.saxon.query.XQueryExpression.<init>(XQueryExpression.java:62) at net.sf.saxon.query.QueryParser.makeXQueryExpression(QueryParser.java:95) at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:325) at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:383) at net.sf.saxon.Query.doMain(Query.java:359) at net.sf.saxon.Query.main(Query.java:72) Thanks, Marc


Replies (5)

Please register to reply

RE: ClassCastException in ArithmeticExpressio - Added by Anonymous over 18 years ago

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

Thanks. This works correctly with my current build, so it's a bit tricky to investigate. The problem is in establishing a type for an expression that yields an empty sequence. The problem runs fairly deep so it would be rash to claim that it's fixed, but I would need to find other instances in order to investigate it. I'm trying to avoid repeating the type-checking of an expression after rewriting it, which is how this particular case got fixed. Michael Kay

RE: ClassCastException in ArithmeticExpressio - Added by Anonymous over 18 years ago

Legacy ID: #3461196 Legacy Poster: marcvc (marcvc)

Michael, with Saxon8.6.1 we still seem to get a ClassCastException: java.lang.ClassCastException at net.sf.saxon.expr.ArithmeticExpression.typeCheck(ArithmeticExpression.java:157) at net.sf.saxon.query.XQueryFunction.compile(XQueryFunction.java:130) at net.sf.saxon.query.XQueryFunctionLibrary.fixupGlobalFunctions(XQueryFunctionLibrary.java:191) at net.sf.saxon.query.StaticQueryContext.fixupGlobalFunctions(StaticQueryContext.java:1425) at net.sf.saxon.instruct.Executable.fixupQueryModules(Executable.java:559) at net.sf.saxon.query.QueryParser.makeXQueryExpression(QueryParser.java:108) at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:451) at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:509) at net.sf.saxon.Query.doMain(Query.java:340) at net.sf.saxon.Query.main(Query.java:76) Thanks, Marc

RE: ClassCastException in ArithmeticExpressio - Added by Anonymous over 18 years ago

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

I can't reproduce this. Can you tell me more about the environment in which it's running? Michael Kay

RE: ClassCastException in ArithmeticExpressio - Added by Anonymous over 18 years ago

Legacy ID: #3461791 Legacy Poster: marcvc (marcvc)

Here is what I did: - downloaded Saxon 8.6.1, and using the downloaded jar files (i.e. no rebuild from the source code) - using the following JDK: java version "1.4.2" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28) Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode) - OS: Windows XP Professional - Saxon is launched using the following cammand line: java -Xmx512m -cp saxon8.jar;jaxp-api.jar;dom.jar net.sf.saxon.Query saxon.xq !indent=yes We get the following exception. Do these line numbers make sense? java.lang.ClassCastException at net.sf.saxon.expr.ArithmeticExpression.typeCheck(ArithmeticExpression.java:157) at net.sf.saxon.query.XQueryFunction.compile(XQueryFunction.java:130) at net.sf.saxon.query.XQueryFunctionLibrary.fixupGlobalFunctions(XQueryFunctionLibrary.java:191) at net.sf.saxon.query.StaticQueryContext.fixupGlobalFunctions(StaticQueryContext.java:1425) at net.sf.saxon.instruct.Executable.fixupQueryModules(Executable.java:559) at net.sf.saxon.query.QueryParser.makeXQueryExpression(QueryParser.java:108) at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:451) at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:509) at net.sf.saxon.Query.doMain(Query.java:340) at net.sf.saxon.Query.main(Query.java:76) We see the same behaviour with Saxon 8.6 and 8.5.1. The stack trace is the same (beside some of the line numbers of course). With Saxon 8.5 the stack trace is different. Let me know if there is anything else you need. I would be more than happy to provide it. Thanks, Marc

RE: ClassCastException in ArithmeticExpressio - Added by Anonymous over 18 years ago

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

Your original stack trace showed this code was in a free-standing query, but the latest stack trace shows that the code is in a user-defined function, which explains why I wasn't able to reproduce it. I haven't actually managed to find a function wrapper that triggers the error, but I did notice that in the case of a free-standing expression the code isn't being statically evaluated as far as possible: I improved the optimization to do this, and this triggered the ClassCastException at the relevant line of code, which I have now fixed. The problem essentially occurs when an operand of an arithmetic expression has a statically-deducible cardinality of "always empty", but where the operand is not explicitly ().

    (1-5/5)

    Please register to reply