mohankreddy / crawler4j

Automatically exported from code.google.com/p/crawler4j
0 stars 0 forks source link

WebURL overrides equals method without overriding hashCode as well #178

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Failing to do so breaks the equals contract and produces erratic behavior when 
using WebURLs in hash-based collections (HashMap, HashSet, etc), since buckets 
will be based on the default Object.hashCode() method, which is not what we 
want to ensure that hashmap lookup works consistently right. According to Java 
API Docs:

As much as is reasonably practical, the hashCode method defined by class Object 
does return distinct integers for distinct objects. (This is typically 
implemented by converting **the internal address of the object into an 
integer**, but this implementation technique is not required by the JavaTM 
programming language.)

An appropriate hashCode() method using the same state as the current 
equals(Object) method might be:

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 41 * hash + (this.url != null ? this.url.hashCode() : 0);
        return hash;
    }

What version of the product are you using?
3.4.1-SNAPSHOT

Please provide any additional information below.

http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html#hashCode()

http://books.google.com.ar/books?id=ka2VUBqHiWkC&pg=PA45&lpg=PA45&dq=effective+j
ava+override+hashCode&source=bl&ots=yYHhOmw_S2&sig=eDhb9_-Yv_qu7-Kjkk4au7leFHI&h
l=en&sa=X&ei=D2agUPTUKo3S9ASs7YHwCQ&ved=0CEEQ6AEwBQ#v=onepage&q=effective%20java
%20override%20hashCode&f=false

Original issue reported on code.google.com by lisandr...@gmail.com on 12 Nov 2012 at 3:08

GoogleCodeExporter commented 9 years ago
Fixed on v3.5

Thank you.

Original comment by avrah...@gmail.com on 11 Aug 2014 at 8:39