You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Owen O'Malley (JIRA)" <ji...@apache.org> on 2011/01/27 19:03:45 UTC

[jira] Commented: (THRIFT-68) Generated types define a hashcode method that always returns 0

    [ https://issues.apache.org/jira/browse/THRIFT-68?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12987675#action_12987675 ] 

Owen O'Malley commented on THRIFT-68:
-------------------------------------

This seems like a very odd behavior and I just got surprised by it. Why does thrift need the hashcode option instead of always generating it?

If Thrift needs the option, you'd be much better off throwing unsupported operation rather than using 0. That way users will find the problem the first time they use the object in a context where you need hashCode.

> Generated types define a hashcode method that always returns 0
> --------------------------------------------------------------
>
>                 Key: THRIFT-68
>                 URL: https://issues.apache.org/jira/browse/THRIFT-68
>             Project: Thrift
>          Issue Type: Bug
>          Components: Java - Compiler, Java - Library
>            Reporter: Bryan Duxbury
>            Priority: Minor
>
> When not using the "hashcode" option with the Java generator, the hashCode method that is created always returns 0, regardless of the type or instance. This makes it completely impossible to use as a hash key (or in a hash set). This is particularly curious because the default Java Object#hashCode method returns a reasonably unique hashcode per object instance. Thus, the hashCode method on generated types is actually explicitly worse than default. 
> I think at the very least we should remove the hashCode method declaration and let the superclass method take care of it. At best, I think it would make sense for us to write a simple real hashCode method that produced something reasonably unique, if not perfect. If you need super hashCodes, then you can use the "hashcode" option and just plan on using the external jar that it requires.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.