Bug #2456
closed"compileLibrary" fails for file with private variable
100%
Description
compileLibrary fails with NullPointer for xquery files with private variable.
java.lang.NullPointerException
at net.sf.saxon.query.QueryModule.bindVariable(QueryModule.java:1090)
at net.sf.saxon.expr.parser.XPathParser.parseVariableReference(XPathParser.java:1905)
at net.sf.saxon.expr.parser.XPathParser.parseBasicStep(XPathParser.java:1703)
at net.sf.saxon.expr.parser.XPathParser.parseStepExpression(XPathParser.java:1638)
at net.sf.saxon.expr.parser.XPathParser.parseRelativePath(XPathParser.java:1564)
at net.sf.saxon.expr.parser.XPathParser.parsePathExpression(XPathParser.java:1529)
at net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(XPathParser.java:1541)
at net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(XPathParser.java:1419)
at net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:511)
at com.saxonica.ee.update.XQueryParserEE.parseExprSingle(XQueryParserEE.java:129)
at net.sf.saxon.expr.parser.XPathParser.parseExpression(XPathParser.java:450)
at net.sf.saxon.query.XQueryParser.parseFunctionDeclaration(XQueryParser.java:2063)
at net.sf.saxon.query.XQueryParser.parseProlog(XQueryParser.java:779)
at net.sf.saxon.query.XQueryParser.parseLibraryModule(XQueryParser.java:445)
at com.saxonica.ee.optim.StaticQueryContextEE.compileLibrary(StaticQueryContextEE.java:160)
at com.saxonica.ee.optim.StaticQueryContextEE.compileLibrary(StaticQueryContextEE.java:230)
at net.sf.saxon.s9api.XQueryCompiler.compileLibrary(XQueryCompiler.java:516)
at issue.XqueryPrivateMapIssueTest.shouldBeAbleToCompileWithCompileLibraryMethod(XqueryPrivateMapIssueTest.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Please see attached XqueryPrivateVariableIssueTest.
In order to run it please add saxon license to resources directory.
Files
Updated by O'Neil Delpratt about 9 years ago
- Status changed from New to In Progress
Thank you for reporting this issue you found and supplying the repo. I have managed to reproduce it. We are investigating the issue and will report back.
Updated by O'Neil Delpratt about 9 years ago
I am not yet sure on the cause of the problem, but it is failing when we try to get the system Id on the global variable private_map_nullpointer:privateMap
It is related in the use of the annotation %private
The other issue is the query is supplied to the XQueryCompiler as a inputStream. At this point Saxon does not have any information about the baseURI.
Updated by O'Neil Delpratt about 9 years ago
Hi,
What you have to do is set the base URI on the XQueryCompiler. Something like the example below:
XQueryCompiler compiler = compiler();
compiler.setBaseURI(new URI("file://private_variable_nullpointer_issue.xq"));
compiler.compileLibrary(getClass().getClassLoader().getResourceAsStream("private_variable_nullpointer_issue.xq"));
I will leave this bug issue open because it should not throw a null pointer exception but should fail in a clean manner.
Updated by Mariusz B about 9 years ago
Thanks! Setting base uri solves the problem but as you suggested it would be nice to have some exception different than NPE in such case.
Updated by Michael Kay about 9 years ago
- Category set to s9api API
- Status changed from In Progress to Resolved
- Assignee set to O'Neil Delpratt
I have patched this for 9.6 and 9.7 so that when the condition occurs, we no long throw an NPE but a specific message.
I'm sticking for the moment to the policy that we allow you to run with an unknown base URI and only report a problem if you do something where the base URI is actually needed. However, setting the base URI is always good practice even if it never gets used.
Updated by O'Neil Delpratt almost 9 years ago
- Status changed from Resolved to Closed
- % Done changed from 0 to 100
- Fixed in version set to 9.6.0.8
Bug fix applied in the Saxon 9.6.0.8 maintenance release
Updated by O'Neil Delpratt almost 9 years ago
- Applies to branch 9.6 added
- Fix Committed on Branch 9.6 added
- Fixed in Maintenance Release 9.6.0.8 added
Please register to edit this issue