“uncaught illegal access” exception in Android browser on JSON.parse()

I recently had a problem where a web app that worked fine on the iPhone, iPhone Simulator, Safari Mac, Safari Windows, Chrome and the Android Emulator would not work at all on any Android device. After tracking down someone who had an Android phone and was able to debug the app, we discovered:

Console: Uncaught illegal access 

in the debugging output that was eventually traced back to a JSON.parse() call that had a null parameter. On all other platforms this returns null, on the Android device it throws an exception. See this bug report for details.

Moral of the story? Always explicitly check your parameter to JSON.parse() for null… and don’t trust the emulator!

Advertisements

10 thoughts on ““uncaught illegal access” exception in Android browser on JSON.parse()

  1. Im experiencing the same problem. But it gets weirder in my case. Its working in the case im running Android Emulator on Linux but fails when i run the emulator on Windows….
    I guess i’ll just add a check for JSON.parse null parameter then… 😦

  2. In my case, its a little different. Its working on android emulator. But when I run it on any Android Mobile, it gives error “uncaught illegal access” at the line when I am doing

    var menuJSON = JSON.parse(window.demo.function1(currentID));

    function1 is not returns a JSONObject and it is not null.
    Any help?

  3. Ran into the same error … thought it was something to do with JSON / localStorage…. Googled it and ended up here.

    Easy fix –
    if ( localStorage.getItem(“something”)){
    things = JSON.parse(localStorage.getItem(“something”));
    }else{
    things = [];
    }

    Kind of sucks because you can’t use the shorthand but better than a fatal bug!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s