Bug #4490
closedNPE in getItemType if type hierarchy is null for merged maps.
100%
Description
I have a query that is merging two maps:
map:merge(($module-namespaces, $xquery-namespaces))
Here, the first map has attribute-based keys, while the second has xs:string based keys.
That query succeeds. However, when I call Item.getItemType with a null type hierarchy I get the following exception in Saxon 9.9.1.7:
Caused by: java.lang.NullPointerException
at net.sf.saxon.type.Type.getCommonSuperType(Type.java:374)
at net.sf.saxon.ma.map.HashTrieMap.getItemType(HashTrieMap.java:280)
at net.sf.saxon.ma.map.HashTrieMap.getItemType(HashTrieMap.java:32)
at net.sf.saxon.type.Type.getItemType(Type.java:213)
Looking at the source code for Type.getCommonSuperType at line 374, it is calling
int r = th.relationship(t1, t2);
without checking that th is null (which is allowed per the documentation on Type.getItemType).
This issue is also present in Saxon 10. The only difference is that the return type has changed to Affinity.
Updated by Reece Dunn about 4 years ago
The following is a minimal XQuery example demonstrating this issue:
declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
map:merge((
map:entry(attribute one {"one"}, 1),
map:entry("two", 2)
))
Updated by Michael Kay about 4 years ago
This repro is working for me. How are you running this query?
Updated by Reece Dunn about 4 years ago
Michael Kay wrote:
This repro is working for me. How are you running this query?
I'm running the query via the Java s9api and then calling net.sf.saxon.type.Type.getItemType on the result, passing null as the type hierarchy.
Updated by Michael Kay about 4 years ago
Thanks. Reproduced as unit test TestXQueryEvaluator/testMapItemType
.
Updated by Michael Kay about 4 years ago
- Category set to Internals
- Status changed from New to Resolved
- Assignee set to Michael Kay
- Priority changed from Low to Normal
- Fix Committed on Branch 10, 9.9 added
Patch committed. The method Type.getItemType()
, when applied to a map or array, with no TypeHierarchy
supplied, will now return the generic type map(*)
or array(*)
.
Note that if the item is an external object, the typeHierarchy parameter must be non-null, and we will note this in the Javadoc.
Updated by O'Neil Delpratt almost 4 years ago
- % Done changed from 0 to 100
- Fixed in Maintenance Release 10.1 added
Bug fix committed in the Saxon 10.1 maintenance release.
Updated by O'Neil Delpratt over 3 years ago
- Status changed from Resolved to Closed
- Fixed in Maintenance Release 10.2, 9.9.1.8 added
- Fixed in Maintenance Release deleted (
10.1)
Bug fix applied on the Saxon 9.9.1.8 maintenance release.
Please register to edit this issue