Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unrecoverable stackoverflow error when making upcalls from JavaScript to Java

I've encountered an "unrecoverable stack overflow error" that I can't figure out. From the docs : you need to create an interface object (of any class) and make it known to JavaScript by calling JSObject.setMember().

Here's the Java code sharing and using the interface object :

// somewhere in the code
JSObject window = (JSObject) engine.executeScript("window");
window.setMember("foo", new Foo()); // <-- shares
window.call("testFoo");             // <-- uses

// somewhere else
class Foo {
    public void bar() {
        System.out.println("baz");
    }
}

And here's the JavaScript code using that object :

window.testFoo = function() {
    window.foo.bar();
}

It occurs if I trigger it manually like show above, or if I trigger it through some JavaScript event.

like image 622
Jean-Marie Comets Avatar asked Nov 10 '22 16:11

Jean-Marie Comets


1 Answers

Answer was in the comments, I can't believe I've been trying everything for hours and it was a very quick fix.

Turns out that the exposed interface has to be public.

like image 148
Jean-Marie Comets Avatar answered Nov 14 '22 22:11

Jean-Marie Comets