Project

Profile

Help

Bug #2328

closed

Reflexive extension functions using java.util.List

Added by Michael Kay over 9 years ago. Updated almost 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Saxon extensions
Sprint/Milestone:
Start date:
2015-03-17
Due date:
% Done:

100%

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

Description

Consider the code

Q{java:java.util.List}size( Q{java:myClass}makeEmptyList() )

where makeEmptyList is a Java method that returns "new ArrayList()".

Here List.size() is a non-static ("instance-level") method, and the documentation says that the first argument must be a "Java object", that is a special kind of Item that wraps a Java object, and which can only be obtained from extension functions. This example doesn't work, because although makeEmptyList() returns an instance of java.util.List, this is immediately converted to an XDM empty sequence: so what is passed to List.size() is not a (wrapped) Java object, but an empty sequence.

In previous releases (I've been looking at 9.4) Saxon was actually more liberal than the documentation implied. Although makeEmptyList() returned an empty sequence, the code for calling List.size() would convert this back to a Java object, knowing that a Java object was the required type. In fact the code to do this conversion is still present in 9.6, but it doesn't get this far: the call fails static type checking, because the static type checking follows the rules in the documentation, and requires that the supplied argument is a Java object, without allowing for any conversion.

Please register to edit this issue

Also available in: Atom PDF