bijilsandroid / as3corelib

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

JSON.decode("") throws a TypeError due to null pointer dereference; would be better to throw a JSONParseError #19

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Execute this: JSON.decode("")

What is the expected output? What do you see instead?

The actual output is this exception:

TypeError: Error #1009: Cannot access a property or method of a null object
reference.
    at com.adobe.serialization.json::JSONDecoder/::parseValue()

I'm pretty sure "" is not legal JSON, so it is correct to throw an
exception, but it would be better to throw a JSONParseError, so that users
who are anticipating possibly illegal JSON can write their code like this,
and have it catch the error:

try {
  JSON.decode(blahblah);
} catch (e:JSONParseError) {
  // deal with it
}

The way to fix this is, I think, to change JSONDecoder.parseValue() so that
at the top of the function, before "switch (token.type)", add this code:

  if (token == null)
    tokenizer.parseError("Unexpected end of input");

What version of the product are you using? On what operating system?
.90, on Windows

Please provide any additional information below.

Original issue reported on code.google.com by mmorea...@gmail.com on 27 Mar 2007 at 6:05

GoogleCodeExporter commented 8 years ago
Good catch, and I agree with your proposed fix as well.  I'll wrap this up in a 
test
case and get the fix in the trunk in the next few days.  I don't believe "" is 
valid
JSON either.

Original comment by darron.schall on 5 Apr 2007 at 10:31

GoogleCodeExporter commented 8 years ago
This was fixed in revision 37.

Original comment by darron.schall on 30 Apr 2007 at 1:45