Bug #2711
closedUnsupportedOperationException when compiling XPath with JAXP NamespaceContext
100%
Description
While upgrading to Saxon-EE 9.7, I found that this code snippet now throws an UnsupportedOperationException:
XPath xpath = new XPathFactoryImpl().newXPath();
xpath.setNamespaceContext(namespaceContext);
xpath.compile("//*:x");
where namespaceContext is a javax.xml.namespace.NamespaceContext.
Here is a stack trace:
Exception in thread "main" java.lang.UnsupportedOperationException
at net.sf.saxon.xpath.JAXPXPathStaticContext.iteratePrefixes(JAXPXPathStaticContext.java:165)
at net.sf.saxon.expr.parser.RetainedStaticContext.<init>(RetainedStaticContext.java:85)
at net.sf.saxon.sxpath.AbstractStaticContext.makeRetainedStaticContext(AbstractStaticContext.java:109)
at net.sf.saxon.expr.parser.XPathParser.parse(XPathParser.java:472)
at net.sf.saxon.expr.parser.ExpressionTool.make(ExpressionTool.java:99)
at net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:194)
A complete program reproducing this is attached.
Files
Updated by Michael Kay over 8 years ago
Thanks. The fact that you can't discover/enumerate all the namespace bindings in a JAXP NamespaceContext is one of the lousiest "features" of this lousy API, but I thought we had found a way around it. Will look into it.
Updated by Michael Kay over 8 years ago
- Category set to JAXP Java API
- Status changed from New to In Progress
- Assignee set to O'Neil Delpratt
Indeed the code contains an ingenious workaround for the JAXP NamespaceContext problem, but the workaround turns out to be inactive because it was accidentally disabled by preprocessor tags added in order to make the .NET build work. (See RetainedStaticContext.JAXPStaticContextCheck). Unfortunately most of our unit testing is done in a development environment where this doesn't show up as a problem, and we didn't have any tests on the final production build that revealed the issue.
Updated by O'Neil Delpratt over 8 years ago
- Status changed from In Progress to Resolved
- % Done changed from 0 to 100
- Fix Committed on Branch 9.7 added
Bug fixed by removing the preprocessor directives. Committed to subversion on the 9.7 and the development branches.
Updated by O'Neil Delpratt over 8 years ago
This fix has caused problems in the .NET build. I have refactored the fix into a method on the Platform. This allows us to do different things on the Java and on .NET.
Updated by O'Neil Delpratt over 8 years ago
- Status changed from Resolved to Closed
- Fixed in Maintenance Release 9.7.0.5 added
Bug fix applied in the Saxon 9.7.0.5 maintenance release.
Please register to edit this issue