Bug #3723
Updated by Michael Kay about 6 years ago
Reported by direct email to MHK.
The essence is a call to a user-defined function which is returning an external Java object:
<pre>
<xsl:function as="jt:java.util.zip.ZipOutputStream" name="test:zos">
<xsl:param as="xs:string" name="path" />
....
<xsl:sequence select="ZipOutputStream:new($fos)" />
</xsl:function>
</pre>
where the external object then has an extension function applied to it:
<pre>
<xsl:variable name="zos"
select="Q{java:java.util.zip.ZipOutputStream?void=this}setComment(test:zos(xxxx), 'comment')" />
</pre>
This is working fine when directly, but fails when running from a SEF file, with the error:
<pre>
java.lang.IllegalStateException: A Closure can only be read once
at net.sf.saxon.value.Closure.iterate(Closure.java:166)
at com.saxonica.expr.JavaExtensionFunctionCall.iterate(JavaExtensionFunctionCall.java:438)
</pre>
The user-defined-function @test:zos()@ returns a Closure that can only be used once because it thinks the result will only be needed once (it is used as the argument to the setComment() call). However, because of the ?void=this option in the extension function URI, the value is actually used twice: once as the argument to the call, and again as the result of the call.