Java JSONObject#has throwing exception


I'm trying to check if a JSONObject has a specific key. Here is my code:

    JSONObject meta = App.meta();
    int sum = 0;
    JSONObject mapping;
    if(!meta.has("readMessagesMap")){  <--- this line jumps to...
        return 0;        <--- never called
        try { <--- never called
            mapping = meta.getJSONObject("readMessagesMap");
            return sum;
        } catch (JSONException e) {
            return 0; <--- ...directly to here

meta is a valid JSONObject:

enter image description here

When I'm stepping, the if statement, somehow, directly jumps to return 0 line inside the catch block, without even entering try block. I have breakpoints on the try line, e.printStackTrace line, they are just not called. The stack trace isn't printed either. I have no idea why this is happening. I've restarted Android Studio and my app, but it's the same.


It was a symbol corruption issue. I've cleaned the project and it got away.

This video can help you solving your question :)
By: admin