#647 ClassCastException with indexed filter in Saxon-SA

v8.8
closed
Michael Kay
5
2012-10-08
2007-01-28
Michael Kay
No

Following query results in a ClassCastException with Saxon SA 8.8

fn:doc("foo.xml")/a/b[2][./@c = "c"]

java.lang.ClassCastException: net.sf.saxon.query.StaticQueryContext
at net.sf.saxon.pattern.LocationPathPattern.analyze(LocationPathPattern.java:178)
at com.saxonica.extra.OptimizerSA.convertFilterExpressionToKey(OptimizerSA.java:277)
at com.saxonica.extra.OptimizerSA.convertPathExpressionToKey(OptimizerSA.java:209)

Specifically, the error occurs with an expression that is a candidate for automatic indexing if the path to be indexed (here /a/b[2]) contains a positional filter.

Source code fix: change line 178 of LocationPathPattern.java from

((ExpressionContext) env).getStyleElement().allocateSlots(equivalentExpr);

to

if (env instanceof ExpressionContext) {
((ExpressionContext) env).getStyleElement().allocateSlots(equivalentExpr);
}

The source fix will be placed in Subversion (although it only affects Saxon-SA and will not therefore be effective without a Saxon-SA rebuild)

Discussion