hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Audley (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing
Date Wed, 02 Aug 2006 17:17:14 GMT
    [ http://issues.apache.org/jira/browse/HTTPCLIENT-593?page=comments#action_12425299 ] 
            
Chris Audley commented on HTTPCLIENT-593:
-----------------------------------------

Roland, there is no working subclass of either of these classes that would be effected by
my proposed changes.  If a subclass does not explicitly override equals, it will be broken.
 For instance, a subclass not overriding equals will not be equal to itself.

Technically, such a class should not work in a HashMap or HashSet.  Fortunately, the Hash
implementations look for object identity before testing equality, so they may work but only
because the equals method will not be used.  However, if a program creates separate instances
of the ProtocolSocketFactory, things will break.

Since the current equals can not work for a subclass, any working subclass must have overridden
it.  Especially if those subclasses don't intend for all instances to be equal.  Applying
this fix can not affect those subclasses and only allows for new subclasses to be implemented
in a correct manner without having to re-implement equals and hashCode.

It may not be a big deal to have to override those methods, but it is annoying, error prone
and unnecessary.

> ProtocolSocketFactory equals and hashCode don't support subclassing
> -------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-593
>                 URL: http://issues.apache.org/jira/browse/HTTPCLIENT-593
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: Nightly Builds, 3.1 Alpha 1
>            Reporter: Chris Audley
>            Priority: Minor
>             Fix For: 4.0 Alpha 1
>
>
> In the implemenation of equals and hashCode for the classes
> org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory
> org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory
> The implementation of equals and hashCode attempts to make all instances of the classes
equal.  However, the manner in which the methods are coded makes it necessary for any subclass
to implement equals and hashCode themselves.  A minor change to the methods in these classes
will make possible to subclass these factories without re-implementing the equals and hashCode.
 The method equals should be written as
>         return ((obj != null) && obj.getClass().equals(getClass()));
> rather than
>         return ((obj != null) && obj.getClass().equals(DefaultProtocolSocketFactory.class));
> And similarly, the hashCode method should be
>         return getClass().hashCode();
> rather than
>         return DefaultProtocolSocketFactory.class.hashCode();

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org


Mime
View raw message