Rhino + JSON.js throwing StackOverflowError when trying to stringify Java objects

44 views
Skip to first unread message

Samuel Wan

unread,
May 15, 2009, 4:19:00 PM5/15/09
to he...@googlegroups.com
Hi Hannes,

I'm waiting to confirm a new account on the Bugzilla server. Meanwhile, wondered if you or anyone else on the list could comment on why sometimes Rhino has difficulty converting Functions to JSON strings.

The CouchDB test suite throws many StackOverflowErrors because the module/core/JSON.js library has difficulty converting Java objects into JSON, leading to an infinite loop. A bunch of JVM errors start spewing in the console, eventually ending with an out-of-memory error: "Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space at java.lang.Object.clone(Native Method)"

I don't understand how the javascript-to-Java conversion works, but an old blog post describes the problem and a solution: http://www.cosmocode.de/en/blogs/detman/json_rhino_pitfalls/

There's an object conversion function starting at line 99 in <helma>/modules/core/JSON.js. I added his fix at line 104 to skip the error:

---------------- JSON.js ----------------
object: function (x) {
   if (x) {
       if (x instanceof Array) {
           return s.array(x);
       }
       if (x.hashCode) return s.string(''+x.toString()); // <-- added this line
--------------------------------------------

I followed the stacktrace to Rhino having difficulties with Function.toSource or Function.toString. However, I can't figure out why some functions will stringify and others won't. Is it related to this other Rhino bug? http://dev.helma.org/bugs/show_bug.cgi?id=545

After this fix, many of the CouchDB tests still assert (maybe due to Rhino's incompatible Function.toString() output), but at least they don't crash anymore.

-Sam

Hannes Wallnoefer

unread,
May 16, 2009, 5:56:40 AM5/16/09
to he...@googlegroups.com
2009/5/15 Samuel Wan <samu...@gmail.com>:
> Hi Hannes,
>
> I'm waiting to confirm a new account on the Bugzilla server. Meanwhile,

I'm not sure what you mean by that. Account creation should be
instantaneous. Maybe check your spam folder for subject "Bugzilla:
confirm account creation".

No idea about the JSON stuff, sorry.

Hannes
Reply all
Reply to author
Forward
0 new messages