You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Chris Audley (JIRA)" <ji...@apache.org> on 2006/08/02 18:17:16 UTC

[jira] Created: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

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: 3.1 Alpha 1, Nightly Builds
            Reporter: Chris Audley
            Priority: Minor


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


[jira] Updated: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HTTPCLIENT-593?page=all ]

Oleg Kalnichevski updated HTTPCLIENT-593:
-----------------------------------------

    Attachment: socketfactory.patch

I'll commit this patch in a few days if no one complains loudly

Oleg

> 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: 3.1 Alpha 1, Nightly Builds
>            Reporter: Chris Audley
>            Priority: Minor
>             Fix For: 3.1 Beta 1
>
>         Attachments: socketfactory.patch
>
>
> 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


[jira] Commented: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

Posted by "Roland Weber (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HTTPCLIENT-593?page=comments#action_12425284 ] 
            
Roland Weber commented on HTTPCLIENT-593:
-----------------------------------------

This will change the behavior for existing subclasses that do NOT override hashCode and equals and for which NOT all instances are supposed to be equal. Overriding those methods is not a big deal. I am -0 on this change for a minor version upgrade. Different story for 4.0.

cheers,
   Roland


> 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: 3.1 Beta 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


[jira] Updated: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HTTPCLIENT-593?page=all ]

Oleg Kalnichevski updated HTTPCLIENT-593:
-----------------------------------------

    Fix Version/s: 3.1 Beta 1

We'll happily accept a patch.

Oleg

> 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: 3.1 Beta 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


[jira] Commented: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

Posted by "Chris Audley (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HTTPCLIENT-593?page=comments#action_12425319 ] 
            
Chris Audley commented on HTTPCLIENT-593:
-----------------------------------------

No Oleg, not a good point!  This should be fixed in the Beta1.

To help illustrate some of the problems with the equals method, play around with this little test program.

    public static void main(String[] args) {
        ProtocolSocketFactory factory1 = new DefaultProtocolSocketFactory();
        ProtocolSocketFactory factory2 = new DefaultProtocolSocketFactory() {};

        Protocol protocolA = new Protocol("http", factory1, 80);
        Protocol protocolB = new Protocol("http", factory2, 80);
        Protocol protocolC = new Protocol("http", factory2, 80);

        if (!protocolB.equals(protocolC))
            System.out.println("Hey! protocolB doesn't equal protocolC");
        if (!protocolA.equals(protocolB))
            System.out.println("Whew, protocolA != protocolB!!!");
        if (protocolB.equals(protocolA))
            System.out.println("What! protocolB == protocolA!!!");
        if (protocolA.equals(protocolB) != protocolB.equals(protocolA))
            System.out.println("Oh no! equals isn't reflexive");
        if (!protocolB.equals(protocolB))
            System.out.println("Uh, You may want to fix this");
    }

Notice that factory2 is a subclass of DefaultProtocolSocketFactory.  The first instance of Protocol (protocolA) should not be equal to protocolB or protocolC, which should be equal to each other.  As you'll see when you run the program, this is not the case.  Every single one of the println methods will be run.

May favorite error is the last one.

> 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


[jira] Commented: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HTTPCLIENT-593?page=comments#action_12425330 ] 
            
Oleg Kalnichevski commented on HTTPCLIENT-593:
----------------------------------------------

Chris,
(1) Roland does have a point in pointing out that this change _may_ alter behaviour of existing applications, which is certainly not something to be expected from a minor release
(2) Subclasses are _always_ expected to correctly implement #hashCode and #equals
(3) ProtocolSocketFactory javadoc explicitly states #hashCode and #equals methods should be overridden for correct operation of some connection managers.

Having said all that, I am +1 for the change, but will not insist on including the fix into 3.1 unless Roland retracts his -0

Oleg

> 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


[jira] Commented: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

Posted by "Roland Weber (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HTTPCLIENT-593?page=comments#action_12425329 ] 
            
Roland Weber commented on HTTPCLIENT-593:
-----------------------------------------

>   if (protocolB.equals(protocolA))
>            System.out.println("What! protocolB == protocolA!!!"); 
>   if (!protocolB.equals(protocolB))
>            System.out.println("Uh, You may want to fix this");

These are good enough to convince me. The others were not.

The contracts for equals and hasCodes were problematic in the very first version of Java, and have even been changed in later versions because of that. You can't expect them to be implemented correctly everywhere. But since protocols have to be compared to eachother, it's better to implement this change.  

cheers and thanks,
  Roland


> 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


[jira] Updated: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HTTPCLIENT-593?page=all ]

Oleg Kalnichevski updated HTTPCLIENT-593:
-----------------------------------------

    Fix Version/s: 4.0 Alpha 1
                       (was: 3.1 Beta 1)

Good point, actually

Oleg

> 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


[jira] Commented: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

Posted by "Roland Weber (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HTTPCLIENT-593?page=comments#action_12425337 ] 
            
Roland Weber commented on HTTPCLIENT-593:
-----------------------------------------

> Having said all that, I am +1 for the change, but will not insist on including the fix into 3.1 unless Roland retracts his -0 

already done :-) I am +1 now.

> 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


[jira] Commented: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

Posted by "Ortwin Glück (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HTTPCLIENT-593?page=comments#action_12425306 ] 
            
Ortwin Glück commented on HTTPCLIENT-593:
-----------------------------------------

+1 for the change

> 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


[jira] Updated: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HTTPCLIENT-593?page=all ]

Oleg Kalnichevski updated HTTPCLIENT-593:
-----------------------------------------

    Fix Version/s: 3.1 Beta 1
                       (was: 4.0 Alpha 1)

Oh, and by the way, did I mention we would happily accept a patch? ;-)

Oleg

> 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: 3.1 Beta 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


[jira] Assigned: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HTTPCLIENT-593?page=all ]

Oleg Kalnichevski reassigned HTTPCLIENT-593:
--------------------------------------------

    Assignee: Oleg Kalnichevski

> 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: 3.1 Alpha 1, Nightly Builds
>            Reporter: Chris Audley
>         Assigned To: Oleg Kalnichevski
>            Priority: Minor
>             Fix For: 3.1 Beta 1
>
>         Attachments: socketfactory.patch
>
>
> 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


[jira] Resolved: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HTTPCLIENT-593?page=all ]

Oleg Kalnichevski resolved HTTPCLIENT-593.
------------------------------------------

    Resolution: Fixed

Patch checked in

Oleg

> 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
>         Assigned To: Oleg Kalnichevski
>            Priority: Minor
>             Fix For: 3.1 Beta 1
>
>         Attachments: socketfactory.patch
>
>
> 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


[jira] Commented: (HTTPCLIENT-593) ProtocolSocketFactory equals and hashCode don't support subclassing

Posted by "Chris Audley (JIRA)" <ji...@apache.org>.
    [ 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