Actions
Bug #6605
closedQuery using static-base-uri() compiled from string gives saxonche.PySaxonApiError: NullPointer exception found: java.lang.NullPointerException
Start date:
2024-12-07
Due date:
% Done:
100%
Estimated time:
Applies to branch:
12, trunk
Fix Committed on Branch:
12, trunk
Fixed in Maintenance Release:
Found in version:
Fixed in version:
SaxonC Languages:
All
SaxonC Platforms:
All
SaxonC Architecture:
Description
The Python program
from saxonche import *
from pathlib import Path
xquery1 = '"Static base uri : " || static-base-uri()'
with PySaxonProcessor() as saxon_proc:
print(saxon_proc.version)
xqueryProcessor = saxon_proc.new_xquery_processor()
workingDirPath = str(Path.cwd().absolute())
print(workingDirPath)
xqueryProcessor.set_cwd(workingDirPath)
result = xqueryProcessor.run_query_to_string(query_text=xquery1)
print(result)
crashes for me under both Windows and Linux.
Using the command Query I can run such a query, however, so the bug might be related to xqueryProcessor.set_cwd
not working as intended.
Output on Windows:
Traceback (most recent call last):
File "C:\Users\marti\PycharmProjects\SaxonC12CompileXsltFromStringTest1\compileXQueryFromStringTest3.py", line 18, in <module>
result = xqueryProcessor.run_query_to_string(query_text=xquery1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "python_saxon\saxonc.pyx", line 3028, in saxonche.PyXQueryProcessor.run_query_to_string
saxonche.PySaxonApiError: NullPointer exception found: java.lang.NullPointerException
at java.base@11.0.18/java.util.Objects.requireNonNull(Objects.java:221)
at net.sf.saxon.str.StringView.<init>(StringView.java:26)
at net.sf.saxon.str.StringView.tidy(StringView.java:39)
at net.sf.saxon.value.AnyURIValue.<init>(AnyURIValue.java:48)
at net.sf.saxon.functions.StaticBaseUri.makeFunctionCall(StaticBaseUri.java:31)
at net.sf.saxon.functions.registry.BuiltInFunctionSet.bind(BuiltInFunctionSet.java:246)
at net.sf.saxon.functions.FunctionLibraryList.bind(FunctionLibraryList.java:133)
at net.sf.saxon.expr.parser.XPathParser.parseFunctionCall(XPathParser.java:4132)
at net.sf.saxon.expr.parser.XPathParser.parseBasicStep(XPathParser.java:2865)
at net.sf.saxon.expr.parser.XPathParser.parseStepExpression(XPathParser.java:2633)
at net.sf.saxon.expr.parser.XPathParser.parseRelativePath(XPathParser.java:2552)
at net.sf.saxon.expr.parser.XPathParser.parsePathExpression(XPathParser.java:2514)
at net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(XPathParser.java:2528)
at net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(XPathParser.java:2378)
at net.sf.saxon.expr.parser.XPathParser.parseBinaryExpression(XPathParser.java:977)
at net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:861)
at net.sf.saxon.expr.parser.XPathParser.parseExpression(XPathParser.java:759)
at net.sf.saxon.query.XQueryParser.parseQuery(XQueryParser.java:381)
at net.sf.saxon.query.XQueryParser.makeXQueryExpression(XQueryParser.java:171)
at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:569)
at net.sf.saxon.s9api.XQueryCompiler.compile(XQueryCompiler.java:651)
at net.sf.saxon.option.cpp.XQueryEngine.xqueryEvaluator(XQueryEngine.java:202)
at net.sf.saxon.option.cpp.XQueryEngine.executeQueryToString(XQueryEngine.java:302)
. Line number: -1
SaxonC-HE 12.5 from Saxonica
C:\Users\marti\PycharmProjects\SaxonC12CompileXsltFromStringTest1
Output on Linux:
SaxonC-HE 12.5 from Saxonica
/mnt/c/Users/marti/PycharmProjects/SaxonC12CompileXsltFromStringTest1
Traceback (most recent call last):
File "/mnt/c/Users/marti/PycharmProjects/SaxonC12CompileXsltFromStringTest1/compileXQueryFromStringTest3.py", line 18, in <module>
result = xqueryProcessor.run_query_to_string(query_text=xquery1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "python_saxon/saxonc.pyx", line 3028, in saxonche.PyXQueryProcessor.run_query_to_string
saxonche.PySaxonApiError: NullPointer exception found: java.lang.NullPointerException
at java.base@11.0.18/java.util.Objects.requireNonNull(Objects.java:221)
at net.sf.saxon.str.StringView.<init>(StringView.java:26)
at net.sf.saxon.str.StringView.tidy(StringView.java:39)
at net.sf.saxon.value.AnyURIValue.<init>(AnyURIValue.java:48)
at net.sf.saxon.functions.StaticBaseUri.makeFunctionCall(StaticBaseUri.java:31)
at net.sf.saxon.functions.registry.BuiltInFunctionSet.bind(BuiltInFunctionSet.java:246)
at net.sf.saxon.functions.FunctionLibraryList.bind(FunctionLibraryList.java:133)
at net.sf.saxon.expr.parser.XPathParser.parseFunctionCall(XPathParser.java:4132)
at net.sf.saxon.expr.parser.XPathParser.parseBasicStep(XPathParser.java:2865)
at net.sf.saxon.expr.parser.XPathParser.parseStepExpression(XPathParser.java:2633)
at net.sf.saxon.expr.parser.XPathParser.parseRelativePath(XPathParser.java:2552)
at net.sf.saxon.expr.parser.XPathParser.parsePathExpression(XPathParser.java:2514)
at net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(XPathParser.java:2528)
at net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(XPathParser.java:2378)
at net.sf.saxon.expr.parser.XPathParser.parseBinaryExpression(XPathParser.java:977)
at net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:861)
at net.sf.saxon.expr.parser.XPathParser.parseExpression(XPathParser.java:759)
at net.sf.saxon.query.XQueryParser.parseQuery(XQueryParser.java:381)
at net.sf.saxon.query.XQueryParser.makeXQueryExpression(XQueryParser.java:171)
at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:569)
at net.sf.saxon.s9api.XQueryCompiler.compile(XQueryCompiler.java:651)
at net.sf.saxon.option.cpp.XQueryEngine.xqueryEvaluator(XQueryEngine.java:202)
at net.sf.saxon.option.cpp.XQueryEngine.executeQueryToString(XQueryEngine.java:302)
. Line number: -1
Files
Related issues
Updated by Martin Honnen 14 days ago
The problem seems to be in the underlying C++ code as well as a code like
std::cout << "Testing static-base-uri function from XQueryProcessor" << std::endl;
XQueryProcessor* xqueryProcessor = saxonProc->newXQueryProcessor();
xqueryProcessor->setcwd(std::filesystem::current_path().string().c_str());
const char* xquery = "'static base URI in XQuery is: ' || static-base-uri()";
xqueryProcessor->setQueryContent(xquery);
try {
std::cout << xqueryProcessor->runQueryToString() << std::endl;
}
catch (SaxonApiException& exception) {
std::cout << "Exception: " << exception.what() << std::endl;
}
outputs a similar stack trace with e.g.
Testing static-base-uri function from XQueryProcessor
Exception: NullPointer exception found: java.lang.NullPointerException
at java.base@11.0.18/java.util.Objects.requireNonNull(Objects.java:221)
at net.sf.saxon.str.StringView.<init>(StringView.java:26)
at net.sf.saxon.str.StringView.tidy(StringView.java:39)
at net.sf.saxon.value.AnyURIValue.<init>(AnyURIValue.java:48)
at net.sf.saxon.functions.StaticBaseUri.makeFunctionCall(StaticBaseUri.java:31)
at net.sf.saxon.functions.registry.BuiltInFunctionSet.bind(BuiltInFunctionSet.java:246)
at net.sf.saxon.functions.FunctionLibraryList.bind(FunctionLibraryList.java:133)
at net.sf.saxon.expr.parser.XPathParser.parseFunctionCall(XPathParser.java:4132)
at net.sf.saxon.expr.parser.XPathParser.parseBasicStep(XPathParser.java:2865)
at net.sf.saxon.expr.parser.XPathParser.parseStepExpression(XPathParser.java:2633)
at net.sf.saxon.expr.parser.XPathParser.parseRelativePath(XPathParser.java:2552)
at net.sf.saxon.expr.parser.XPathParser.parsePathExpression(XPathParser.java:2514)
at net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(XPathParser.java:2528)
at net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(XPathParser.java:2378)
at net.sf.saxon.expr.parser.XPathParser.parseBinaryExpression(XPathParser.java:977)
at net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:861)
at net.sf.saxon.expr.parser.XPathParser.parseExpression(XPathParser.java:759)
at net.sf.saxon.query.XQueryParser.parseQuery(XQueryParser.java:381)
at net.sf.saxon.query.XQueryParser.makeXQueryExpression(XQueryParser.java:171)
at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:569)
at net.sf.saxon.s9api.XQueryCompiler.compile(XQueryCompiler.java:651)
at net.sf.saxon.option.cpp.XQueryEngine.xqueryEvaluator(XQueryEngine.java:229)
at net.sf.saxon.option.cpp.XQueryEngine.executeQueryToString(XQueryEngine.java:302)
Updated by O'Neil Delpratt 11 days ago
- Status changed from New to In Progress
- Applies to branch trunk added
Thanks for reporting this issue. I have reproduced it and will report back after investigation.
Updated by O'Neil Delpratt 10 days ago
- Status changed from In Progress to Resolved
- % Done changed from 0 to 100
- Fix Committed on Branch 12, trunk added
- SaxonC Languages All added
In the internals of SaxonC we are not setting the base URI on the XQueryCompiler. Bug now fixed and committed. Test case added to the pytests
Updated by O'Neil Delpratt 9 days ago
- Related to Bug #6606: With XPath, although cwd is set, static-base-uri() is empty added
Please register to edit this issue
Actions