On Fri, 9 Jul 2021 at 13:01, Christian Grün <christian.gruen@gmail.com> wrote:
Hi all, hi Reece,

I have remastered the conversion of Java values: Objects of unknown
type are now returned as function item, and the conversion of the
contained value can be enforced by invoking the function item:

Thanks. I've ported my code over to the latest 9.6 dev release, which is working aside from a strange caching issue.

The following produces the correct output in the BaseX GUI:
---
declare namespace String = "java:java.lang.String";

declare function local:tokenize($text as xs:string) {
  String:split($text, " ")
};

local:tokenize("Lorem ipsum dolor"),
local:tokenize("sed emit consecutor")
---

Note: I'm using `String:split($text, " ")` here as a demonstration of the issue.

However, if I take my https://github.com/rhdunn/document-viewer code running on the BaseX HTTP server (via bin/basexhttp on AdoptOpenJDK 11.0.7+10), and in src/modules/html.xqy add:
---
declare namespace String = "java:java.lang.String";

declare function local:tokenize($text as xs:string) {
  String:split($text, " ")
};
---

and then modify the text() case in html:simplify from:
---
    if (contains($node, "margin-bottom: ")) then
      ()
    else
      $node
---
to
---
    if (contains($node, "margin-bottom: ")) then
      ()
    else
      text { html:tokenize($node) }
---
I just see whitespace (as if it is caching the first $node value). Changing it to:
---
    if (contains($node, "margin-bottom: ")) then
      ()
    else if (normalize-space($node) eq "") then
      $node
    else
      text { html:tokenize($node) }
---
then I see the first non-whitespace text node repeated.

If I then replace the `String:split($text, " ")` call with `tokenize($text)` I don't see the issue, so it seems to be related with the Java interop being cached.

Kind regards,
Reece