AndreasBroager / as3corelib

Automatically exported from code.google.com/p/as3corelib
0 stars 0 forks source link

Error #1023: Stack overflow occurred #86

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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.

Original issue reported on code.google.com by slavi.ma...@gmail.com on 21 Jan 2009 at 10:52