Project

Profile

Help

Problems with migration from saxon-sa 9.1.0.7 to SaxonPE 9.4.0.6 - compiler bugs?

Added by Nikolay Ognyanov over 11 years ago

Hi,

I am trying to migrate from saxon-sa 9.1.0.7 to Saxon-PE 9.4.0.6. Changes in the API are minor and pose no significant challenges. There seem to be however problems with the backward compatibility. Here is what I hit with a script which used to run without glitches:

2013-03-16 15:40:46,440 ERROR TuaregEntry [302031] - net.sf.saxon.expr.CompareToIntegerConstant cannot be cast to net.sf.saxon.expr.BinaryExpression java.lang.ClassCastException: net.sf.saxon.expr.CompareToIntegerConstant cannot be cast to net.sf.saxon.expr.BinaryExpression at net.sf.saxon.s9api.XQueryCompiler.compile(XQueryCompiler.java:502) at com.travelstoremaker.tribe.infra.xml.XMLFactoryImpl.getXQueryExecutable(XMLFactoryImpl.java:453) .........

This seems to be a bug in the compiler since it throws an exception rather than reporting an error in the script (if there is such at all). My practical problem is: I do not know what this means (apart from blurry guesses based on class names) and how did I come to it. So I do not know how to fix it either. The script is too big to hunt the issue by trial and error. Can somebody help with this?

The more general issue here is: to what extent can I trust that scripts (all of the several hundred that I have at hand) which run with the older version will run with the latest version? Any experience/advice about this?

Regards Nikolay


Replies (12)

Please register to reply

RE: Problems with migration from saxon-sa 9.1.0.7 to SaxonPE 9.4.0.6 - compiler bugs? - Added by Michael Kay over 11 years ago

This certainly looks like a bug, and not one that has previously been encountered. If you can give us the information to reproduce it, we will be very glad to look into it.

Of course, finding a bug like this reduces your confidence in the product. However, 9.4 is now very stable and new bugs are rare.

In fact, I think I can already see where the bug is: there are not many places where there is a cast to BinaryExpression and I have found one that is unsafe. (For my own reference, ForExpression line 426). Nevertheless, a repro test case would be most helpful so we can test any patch.

RE: Problems with migration from saxon-sa 9.1.0.7 to SaxonPE 9.4.0.6 - compiler bugs? - Added by Nikolay Ognyanov over 11 years ago

Thank you for the quick response.

I can not provide the complete script but I did manage to trace down the problem to an expression of the following kind:

for $x at $pos in $y where $pos < 6 return ....

If I remove the "where $pos < 6" clause, the problem disappears.

RE: Problems with migration from saxon-sa 9.1.0.7 to SaxonPE 9.4.0.6 - compiler bugs? - Added by Nikolay Ognyanov over 11 years ago

P.S. :

May I please add here another backward compatibility issue which I encountered (after working around the previous) even though it is does not seem to be a compiler bug?

I experience strange issues with access from xquery scripts to java code when running JUnit tests under Maven. What I get is exceptions of the following kind :

net.sf.saxon.s9api.SaxonApiException: Cannot find a matching 1-argument function named {java:com.travelstoremaker.xxx.SomeClass}someMethod()

The same tests run without problems under the Eclipse test runner and also - both in Eclipse and under Maven with Saxon 9.1.0.7.

Any advice?

RE: Problems with migration from saxon-sa 9.1.0.7 to SaxonPE 9.4.0.6 - compiler bugs? - Added by Michael Kay over 11 years ago

(It would probably be better to raise different problems on different threads).

Calls to Java extension functions should work largely unchanged though there have been refinements in the details. The problem may simply be a classpath issue, or it could be that you are not invoking Saxon in a way that activates the Saxon-PE functionality.

If you are running from the command line, use the -TJ option to get diagostics on problems with extension functions.

RE: Problems with migration from saxon-sa 9.1.0.7 to SaxonPE 9.4.0.6 - compiler bugs? - Added by Nikolay Ognyanov over 11 years ago

Sorry about mixing unrelated reports.

I am running Saxon embedded in Java code. It turns out that somehow the license file does not get loaded (specifically under Maven/JUnit) even though it is on the class path. Setting the SAXON_HOME environment variable solves the problem. I will not bother you with this further.

RE: Problems with migration from saxon-sa 9.1.0.7 to SaxonPE 9.4.0.6 - compiler bugs? - Added by Michael Kay over 11 years ago

I haven't managed to reproduce this. I can see where the code is wrong, but I can't find a query that causes the incorrect code to be activated; this is basically because it is doing an optimization that appears on the surface to be redundant, as it was already performed elsewhere. You've obviously stumbled on some condition that means it can't be optimized the first time around, but succeeds at the second attempt. In the circumstances I will commit a defensive patch that simply bypasses the optimization code in the conditions where the ClassCastException would occur.

RE: Problems with migration from saxon-sa 9.1.0.7 to SaxonPE 9.4.0.6 - compiler bugs? - Added by Nikolay Ognyanov over 11 years ago

In my experience reproduction is straightforward. I just tried quickly in oXygen 14.2 (with Saxon 9.4.0.6) the following:

let $y := (1,2,3,4) return for $x at $pos in $y where $pos < 3 return $x

and the result was the already mentioned above class cast exception.

RE: Problems with migration from saxon-sa 9.1.0.7 to SaxonPE 9.4.0.6 - compiler bugs? - Added by Michael Kay over 11 years ago

Thanks for supplying the repro. This has enabled me to reproduce the problem, which was not quite as I had guessed. I have updated the patch accordingly.

RE: Problems with migration from saxon-sa 9.1.0.7 to SaxonPE 9.4.0.6 - compiler bugs? - Added by Nikolay Ognyanov over 11 years ago

Thank you for the quick fix. Any projections as to when a version with the patch may be published?

RE: Problems with migration from saxon-sa 9.1.0.7 to SaxonPE 9.4.0.6 - compiler bugs? - Added by Michael Kay over 11 years ago

No sorry we don't have a projected date at the moment; unfortunately this was reported very soon after 9.4.0.7 went out.

I should have mentioned circumvention: you can work around the problem by changing the query to something like

for $x at $pos in $y[position() < 3]

RE: Problems with migration from saxon-sa 9.1.0.7 to SaxonPE 9.4.0.6 - compiler bugs? - Added by Nikolay Ognyanov over 11 years ago

So the fix is supposed to go to 9.4.0.8 whenever that is published?

RE: Problems with migration from saxon-sa 9.1.0.7 to SaxonPE 9.4.0.6 - compiler bugs? - Added by Michael Kay over 11 years ago

Yes, that's the normal process. In fact 9.5 might be released first. (This bug had actually already been fixed, somewhere along the line, in the 9.5 branch).

    (1-12/12)

    Please register to reply