as3corelib icon indicating copy to clipboard operation
as3corelib copied to clipboard

Error #1023: Stack overflow occurred

Open darronschall opened this issue 15 years ago • 0 comments

Originally filed by slavi.marinov on 2009-01-21T10:52:58

Repro steps:

  1. Try to JSON.encode():

JSON.encode(new Crash());

an object of this class:

class Crash { public function get copy() : Crash { return new Crash(); } }

Expected: I would get an error that this is not supported.

Actual: A stack overflow occurs:

Error: Error #1023: Stack overflow occurred. at com.adobe.serialization.json::JSONEncoder/objectToString() at com.adobe.serialization.json::JSONEncoder/convertToString() at com.adobe.serialization.json::JSONEncoder/objectToString() at com.adobe.serialization.json::JSONEncoder/convertToString() at com.adobe.serialization.json::JSONEncoder/objectToString() ...

Suggestion:

The implementation in JSONEncoder.as can be switched from recursive to iterative by using a stack; This way you can a) support more levels if you wanted to, and b) easily know at which level of the call stack a function is being called. You can then raise a user-friendly error telling the user that class XX contains a recursive member and they need to fix this.

An alternative would be to allow users to write custom serializers for their classes.

I believe both are necessary in order to truly fix this bug.

darronschall avatar Jul 28 '10 20:07 darronschall