Project

Profile

Help

Bug #4490

NPE in getItemType if type hierarchy is null for merged maps.

Added by Reece Dunn over 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Internals
Sprint/Milestone:
-
Start date:
2020-03-21
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
10, 9.9
Fix Committed on Branch:
10, 9.9
Fixed in Maintenance Release:
Platforms:

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.

History

#1 Updated by Reece Dunn over 1 year 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)
))

#2 Updated by Michael Kay over 1 year ago

This repro is working for me. How are you running this query?

#3 Updated by Reece Dunn over 1 year 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.

#4 Updated by Michael Kay over 1 year ago

Thanks. Reproduced as unit test TestXQueryEvaluator/testMapItemType.

#5 Updated by Michael Kay over 1 year 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.

#6 Updated by O'Neil Delpratt over 1 year ago

  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 10.1 added

Bug fix committed in the Saxon 10.1 maintenance release.

#7 Updated by O'Neil Delpratt about 1 year 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

Also available in: Atom PDF