Skip to content

Incorrect equals, hashCode and toString in GenericData #936

Closed

Description

@iirekm

GenericData is the base class for 'requst' and 'response' objects in Google Java API bindings. It inherits equals from AbstractHashMap, which is a mistake. Let's consider this expression (Directory API):

directory.users().list().equals(directory.groups().list())

Intuition says it should be false, but in fact is true, because in this example it happens that both left and right side has exactly the same keys and values in the AbstractHashMap, which makes strange errors for example when somebody tries to put objects to own HashMaps (eg to make some simple caching).

The reason of this problem is that AbstractHashMap.equals and AbstractHashMap.hashCode dosn't take this.getClass() into account (just like all implementations of Map do), but GenericData isn't just a Map, it's just a regular object with generic access mechanism, and IMHO should have valid equals and hashCode implemented.

The same is as for toString: strings like {...} don't tell me of which class this object is, eg is this directory.users().list() request or directory.groups().list() request?

Activity

  1. added
    type: bug
    priority: p2
    and removed on Jun 6, 2018
  2. added
    🚨
    on Jun 8, 2018
  3. sduskis commented on Feb 12, 2019

    @sduskis
  4. added
    type: question
    and removed
    🚨
    priority: p2
    type: bug
    on Feb 12, 2019
  5. ajaaym commented on Feb 12, 2019

    @ajaaym
    Contributor

    GenericData is in google http java client.

  6. added
    type: feature request
    and removed
    type: question
    on Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions