[
https://issues.apache.org/jira/browse/AVRO-182?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12776172#action_12776172
]
Doug Cutting commented on AVRO-182:
-----------------------------------
> I think you should include the instanceof check.
Note that including it at the top-level will not prevent ClassCastException,
since I implemented equals with compareTo(), which may throw this. For
example, a GenericRecord with a value for "foo" that's a float will throw
ClassCastException if it's checked for equality with a GenericRecord whose
value for "foo" is a long. We could to some degree prevent this (at some
performance penality) by first comparing schemas, but even that will fail if an
object doesn't actually validate against its schema. So the only way to really
prevent ClassCastException is to implement equals() independently of
compareTo(), and check with instanceof before each cast. Would you prefer
that? If so, I can implement equals independently.
> I would be very confused by the error.
Really? If you got a ClassCastException when you tried to put something into a
HashMap that wasn't the same class as other stuff in that hash table you'd be
confused? Are you similarly confused when you try to do this with a TreeMap?
Or do you have some other scenario in mind?
> hashCode and equals are not consistent with compareTo
> -----------------------------------------------------
>
> Key: AVRO-182
> URL: https://issues.apache.org/jira/browse/AVRO-182
> Project: Avro
> Issue Type: Bug
> Components: java
> Reporter: Doug Cutting
> Assignee: Doug Cutting
> Fix For: 1.3.0
>
> Attachments: AVRO-182.patch
>
>
> Java's specific and generic APIs implement compareTo according to the schema,
> where some fields might be ignored. To be consistent, fields that are
> ignored when comparing for ordering should also be ignored when comparing for
> equality and for computing hashCodes.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.