Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential call to null.equals(null) in JSONObject. #62

Closed
drguildo opened this issue Jul 29, 2012 · 3 comments
Closed

Potential call to null.equals(null) in JSONObject. #62

drguildo opened this issue Jul 29, 2012 · 3 comments

Comments

@drguildo
Copy link

Both valueToString and writeValue have method calls of the form value.equals(null). If value is equal to null then a call to null.equals(null) is going to fail with a NullPointerException.

@douglascrockford
Copy link
Contributor

Please show me how this can potentially raise a NullPointerException:

if (value == null || value.equals(null)) {
    return "null";
}

@drguildo
Copy link
Author

Sorry, you're right, it can't; but in the case where value is null, the second check (value.equals(null)) is either completely pointless (because the previous check has determined that it is null) or raises a NullPointerException (because it is null and trying to call equals on it results in a NullPointerException).

bsh % String foo = null;
bsh % foo.equals(null);
// Error: // Uncaught Exception: null : at Line: 1 : in file: <unknown file> : foo .equals ( null ) 

Target exception: java.lang.NullPointerException: Null Pointer in Method Invocation

@douglascrockford
Copy link
Contributor

Don't be filing bugs in your code against me.

BGehrels pushed a commit to BGehrels/JSON-java that referenced this issue Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants