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

01/04/2011 § 9 Comments

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!

About these ads

Tagged: , ,

§ 9 Responses to “uncaught illegal access” exception in Android browser on JSON.parse()

  • Naman Anand says:

    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… :-(

  • Erik Reppen - BigTime Software says:

    Thanks for this. No doubt saved us some time.

  • Dhairya Vora says:

    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?

  • Julian says:

    Thank you for this solution!

  • Mark says:

    Thank you! This helped a bunch.

  • Nora says:

    Wow! Thanks for saving our app in 2.2+ ! No emulator I tried had this problem, just the phone itself.

  • Shycon says:

    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!

  • dansmartwebdev says:

    Thanks, this was very useful, a frustrating bug to find!

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 )

Connecting to %s

What’s this?

You are currently reading “uncaught illegal access” exception in Android browser on JSON.parse() at NSCoding.

meta

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: