Skip to content

JSONObject#equals method violates the contract of equals #65

@ralfstx

Description

@ralfstx

The equals method of JSONObject#Null violates the “non-nullity” requirement of the equals method in Java. Since null in Java is not an Object, and does not provide an equals method, null.equals( JSONObject.NULL ) cannot return true while JSONObject.NULL.equals( null ) does so. Hence, this equals implementation is not symetric and violates the contract of an equivalence relation. No object must be equal to null.

Tools like the equals verifier fault this implementation because of this violation. Also the Java Development Tools in Eclipse complain because this class implements equals without implementing hashCode.

Since there is only one single instance of JSONObject#NULL, I'd suggest to remove the equals method from JSONObject#Null. Object#equals is a perfect fit for this class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions