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

Incorrect equals, hashCode and toString in GenericData #936

Closed
iirekm opened this issue Apr 27, 2015 · 2 comments
Closed

Incorrect equals, hashCode and toString in GenericData #936

iirekm opened this issue Apr 27, 2015 · 2 comments
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@iirekm
Copy link

iirekm commented Apr 27, 2015

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?

@mattwhisenhunt mattwhisenhunt added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed status: investigating labels Jun 6, 2018
@JustinBeckwith JustinBeckwith added the 🚨 This issue needs some love. label Jun 8, 2018
@sduskis

This comment has been minimized.

@sduskis sduskis added type: question Request for information or clarification. Not an issue. and removed 🚨 This issue needs some love. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Feb 12, 2019
@ajaaym
Copy link
Contributor

ajaaym commented Feb 12, 2019

GenericData is in google http java client.

@sduskis sduskis added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: question Request for information or clarification. Not an issue. labels Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

6 participants