You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Christoph Kutzinski (JIRA)" <ji...@apache.org> on 2007/08/21 17:46:32 UTC

[jira] Created: (LANG-353) Javadoc Example for EqualsBuilder is questionable

Javadoc Example for EqualsBuilder is questionable
-------------------------------------------------

                 Key: LANG-353
                 URL: https://issues.apache.org/jira/browse/LANG-353
             Project: Commons Lang
          Issue Type: Bug
            Reporter: Christoph Kutzinski
            Priority: Minor


The Javadoc example for the class EqualsBuilder ist questionable:

 public boolean equals(Object obj) {
   if (obj instanceof MyClass == false) {
     return false;
   }
  ...

The implementation with instanceof lacks guarantees like equals-symmetry  (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm  for a discussion of the issue)
The example should be changed to use getClass(). Attention: the solution in the link above is incomplete as it doesn't check for null

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


Re: [jira] Commented: (LANG-353) Javadoc Example for EqualsBuilder is questionable

Posted by Henri Yandell <fl...@gmail.com>.
At a guess, email:

issues-unsubscribe@commons.apache.org

My reply will probably have unsubscribe info at the bottom. For some
reason the automated JIRA emails don't get that.

[I'm going to delete the comment below from JIRA as it's not pertinent
to the issue in question]

On 8/22/07, Or_Daniel@emc.com (JIRA) <ji...@apache.org> wrote:
>
>     [ https://issues.apache.org/jira/browse/LANG-353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12521750 ]
>
> Or_Daniel@emc.com commented on LANG-353:
> ----------------------------------------
>
> Registering to commons.dev added me automatically to
> issues@commons.apache.org.
> Unregistering did not remove me from issues@commons.apache.org.
>
> How do I unregister
>
>
> > Javadoc Example for EqualsBuilder is questionable
> > -------------------------------------------------
> >
> >                 Key: LANG-353
> >                 URL: https://issues.apache.org/jira/browse/LANG-353
> >             Project: Commons Lang
> >          Issue Type: Bug
> >            Reporter: Christoph Kutzinski
> >            Priority: Minor
> >             Fix For: 2.4
> >
> >
> > The Javadoc example for the class EqualsBuilder ist questionable:
> >  public boolean equals(Object obj) {
> >    if (obj instanceof MyClass == false) {
> >      return false;
> >    }
> >   ...
> > The implementation with instanceof lacks guarantees like equals-symmetry  (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm  for a discussion of the issue)
> > The example should be changed to use getClass(). Attention: the solution in the link above is incomplete as it doesn't check for null
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>

[jira] Commented: (LANG-353) Javadoc Example for EqualsBuilder is questionable

Posted by "Or_Daniel@emc.com (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12521750 ] 

Or_Daniel@emc.com commented on LANG-353:
----------------------------------------

Registering to commons.dev added me automatically to
issues@commons.apache.org.
Unregistering did not remove me from issues@commons.apache.org.
 
How do I unregister


> Javadoc Example for EqualsBuilder is questionable
> -------------------------------------------------
>
>                 Key: LANG-353
>                 URL: https://issues.apache.org/jira/browse/LANG-353
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Christoph Kutzinski
>            Priority: Minor
>             Fix For: 2.4
>
>
> The Javadoc example for the class EqualsBuilder ist questionable:
>  public boolean equals(Object obj) {
>    if (obj instanceof MyClass == false) {
>      return false;
>    }
>   ...
> The implementation with instanceof lacks guarantees like equals-symmetry  (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm  for a discussion of the issue)
> The example should be changed to use getClass(). Attention: the solution in the link above is incomplete as it doesn't check for null

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


[jira] Commented: (LANG-353) Javadoc Example for EqualsBuilder is questionable

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12529149 ] 

Henri Yandell commented on LANG-353:
------------------------------------

Yeah, scratch the classloader bit. I dug around a bit and it was with the Enum code and not the Builder code where we were doing such things. With Enums we did want things to be equal across classloaders, but the builders won't care.

I'll update the javadoc with the first example, and a reference to Effective Java.

> Javadoc Example for EqualsBuilder is questionable
> -------------------------------------------------
>
>                 Key: LANG-353
>                 URL: https://issues.apache.org/jira/browse/LANG-353
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Christoph Kutzinski
>            Priority: Minor
>             Fix For: 2.4
>
>
> The Javadoc example for the class EqualsBuilder ist questionable:
>  public boolean equals(Object obj) {
>    if (obj instanceof MyClass == false) {
>      return false;
>    }
>   ...
> The implementation with instanceof lacks guarantees like equals-symmetry  (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm  for a discussion of the issue)
> The example should be changed to use getClass(). Attention: the solution in the link above is incomplete as it doesn't check for null

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


[jira] Commented: (LANG-353) Javadoc Example for EqualsBuilder is questionable

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12537846 ] 

Henri Yandell commented on LANG-353:
------------------------------------

Oops, this has sat on my machine for a while. Now committed:

svn ci -m "Applying the javadoc sample usage change from LANG-353 as reported by Christoph Kutzinski" src/java/org/apache/commons/lang/builder/EqualsBuilder.java

Sending        src/java/org/apache/commons/lang/builder/EqualsBuilder.java
Transmitting file data .
Committed revision 588536.

Prior to closing this, I'm pondering if the EqualsBuilderTest should change to test this pattern too.

> Javadoc Example for EqualsBuilder is questionable
> -------------------------------------------------
>
>                 Key: LANG-353
>                 URL: https://issues.apache.org/jira/browse/LANG-353
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Christoph Kutzinski
>            Priority: Minor
>             Fix For: 2.4
>
>
> The Javadoc example for the class EqualsBuilder ist questionable:
>  public boolean equals(Object obj) {
>    if (obj instanceof MyClass == false) {
>      return false;
>    }
>   ...
> The implementation with instanceof lacks guarantees like equals-symmetry  (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm  for a discussion of the issue)
> The example should be changed to use getClass(). Attention: the solution in the link above is incomplete as it doesn't check for null

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


[jira] Commented: (LANG-353) Javadoc Example for EqualsBuilder is questionable

Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12533915 ] 

Gary Gregory commented on LANG-353:
-----------------------------------

Not to get stuck on the details here, but Enums /are/ different from Classes, and have been made such in Jaav 5. I think of the [lang] enums useful if you cannot use Java 5 enums. I would say that enum elements must be equal across class loaders, otherwise, many an application will have some very odd results. Just imagine, as a simple example, the following (I use the Java 5 notation for brevity):

public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }

CLUBS from one class loader is not the same as... CLUBS from another class loader? Havok in poker-land! ;-)


> Javadoc Example for EqualsBuilder is questionable
> -------------------------------------------------
>
>                 Key: LANG-353
>                 URL: https://issues.apache.org/jira/browse/LANG-353
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Christoph Kutzinski
>            Priority: Minor
>             Fix For: 2.4
>
>
> The Javadoc example for the class EqualsBuilder ist questionable:
>  public boolean equals(Object obj) {
>    if (obj instanceof MyClass == false) {
>      return false;
>    }
>   ...
> The implementation with instanceof lacks guarantees like equals-symmetry  (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm  for a discussion of the issue)
> The example should be changed to use getClass(). Attention: the solution in the link above is incomplete as it doesn't check for null

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


[jira] Closed: (LANG-353) Javadoc Example for EqualsBuilder is questionable

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-353?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed LANG-353.
------------------------------

    Resolution: Fixed

I updated the tests to use this style in r594276.

> Javadoc Example for EqualsBuilder is questionable
> -------------------------------------------------
>
>                 Key: LANG-353
>                 URL: https://issues.apache.org/jira/browse/LANG-353
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Christoph Kutzinski
>            Priority: Minor
>             Fix For: 2.4
>
>
> The Javadoc example for the class EqualsBuilder ist questionable:
>  public boolean equals(Object obj) {
>    if (obj instanceof MyClass == false) {
>      return false;
>    }
>   ...
> The implementation with instanceof lacks guarantees like equals-symmetry  (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm  for a discussion of the issue)
> The example should be changed to use getClass(). Attention: the solution in the link above is incomplete as it doesn't check for null

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


[jira] Commented: (LANG-353) Javadoc Example for EqualsBuilder is questionable

Posted by "Christoph Kutzinski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12529013 ] 

Christoph Kutzinski commented on LANG-353:
------------------------------------------

Yes, that's what I'm suggesting.

And if I understood your second point right - you are suggesting to compare the class names, because the two objects could be loaded in different classloaders:
No, if two classes are loaded by different classloaders, they (and their instances) are never "equal". Even if they are loaded from the same source, i.e. the same .class file.

> Javadoc Example for EqualsBuilder is questionable
> -------------------------------------------------
>
>                 Key: LANG-353
>                 URL: https://issues.apache.org/jira/browse/LANG-353
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Christoph Kutzinski
>            Priority: Minor
>             Fix For: 2.4
>
>
> The Javadoc example for the class EqualsBuilder ist questionable:
>  public boolean equals(Object obj) {
>    if (obj instanceof MyClass == false) {
>      return false;
>    }
>   ...
> The implementation with instanceof lacks guarantees like equals-symmetry  (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm  for a discussion of the issue)
> The example should be changed to use getClass(). Attention: the solution in the link above is incomplete as it doesn't check for null

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


[jira] Commented: (LANG-353) Javadoc Example for EqualsBuilder is questionable

Posted by "Christoph Kutzinski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12533977 ] 

Christoph Kutzinski commented on LANG-353:
------------------------------------------

Without knowing the details again (I don't know which kind of applications you are thinking of): I think if you trying to compare enums from different classloader, that's already the problem you have. I.e. you shouldn't try this as it usually indicates that you have mixed up your classloader hierarchy. So it's better for the enum's equal to fail fast instead of allowing something which shouldn't be done.

But this discussion doesn't really belong here. If you would like to continue it, you can contact me via e-mail: kutzi@gmx.de

> Javadoc Example for EqualsBuilder is questionable
> -------------------------------------------------
>
>                 Key: LANG-353
>                 URL: https://issues.apache.org/jira/browse/LANG-353
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Christoph Kutzinski
>            Priority: Minor
>             Fix For: 2.4
>
>
> The Javadoc example for the class EqualsBuilder ist questionable:
>  public boolean equals(Object obj) {
>    if (obj instanceof MyClass == false) {
>      return false;
>    }
>   ...
> The implementation with instanceof lacks guarantees like equals-symmetry  (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm  for a discussion of the issue)
> The example should be changed to use getClass(). Attention: the solution in the link above is incomplete as it doesn't check for null

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


[jira] Commented: (LANG-353) Javadoc Example for EqualsBuilder is questionable

Posted by "Christoph Kutzinski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12529363 ] 

Christoph Kutzinski commented on LANG-353:
------------------------------------------

Ok.

Do you have an issue id for the Enum thing? My opinion on that - without knowing the details - is that Enums are not much different from classes and therefore enums from different classloaders shouldn't be considered equals. So, I would like to comment on that issue.

> Javadoc Example for EqualsBuilder is questionable
> -------------------------------------------------
>
>                 Key: LANG-353
>                 URL: https://issues.apache.org/jira/browse/LANG-353
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Christoph Kutzinski
>            Priority: Minor
>             Fix For: 2.4
>
>
> The Javadoc example for the class EqualsBuilder ist questionable:
>  public boolean equals(Object obj) {
>    if (obj instanceof MyClass == false) {
>      return false;
>    }
>   ...
> The implementation with instanceof lacks guarantees like equals-symmetry  (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm  for a discussion of the issue)
> The example should be changed to use getClass(). Attention: the solution in the link above is incomplete as it doesn't check for null

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


[jira] Updated: (LANG-353) Javadoc Example for EqualsBuilder is questionable

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-353?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-353:
-------------------------------

    Comment: was deleted

> Javadoc Example for EqualsBuilder is questionable
> -------------------------------------------------
>
>                 Key: LANG-353
>                 URL: https://issues.apache.org/jira/browse/LANG-353
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Christoph Kutzinski
>            Priority: Minor
>             Fix For: 2.4
>
>
> The Javadoc example for the class EqualsBuilder ist questionable:
>  public boolean equals(Object obj) {
>    if (obj instanceof MyClass == false) {
>      return false;
>    }
>   ...
> The implementation with instanceof lacks guarantees like equals-symmetry  (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm  for a discussion of the issue)
> The example should be changed to use getClass(). Attention: the solution in the link above is incomplete as it doesn't check for null

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


[jira] Commented: (LANG-353) Javadoc Example for EqualsBuilder is questionable

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12528976 ] 

Henri Yandell commented on LANG-353:
------------------------------------

Sounds like you're suggesting:

 * public boolean equals(Object obj) {
 *   if (obj == null) { return false; }
 *   if (obj == this) { return true; }
 *   if (obj.getClass() != getClass()) {
 *     return false;
 *   }
 *   MyClass rhs = (MyClass) obj;
 *   return new EqualsBuilder()
 *                 .appendSuper(super.equals(obj))
 *                 .append(field1, rhs.field1)
 *                 .append(field2, rhs.field2)
 *                 .append(field3, rhs.field3)
 *                 .isEquals();
 *  }

Though an issue that we've come across with the builders is what to do with classloaders. So you end up with:

 * public boolean equals(Object obj) {
 *   if (obj == null) { return false; }
 *   if (obj == this) { return true; }
 *   if (!obj.getClass().getName().equals(getClass().getName()) {
 *     return false;
 *   }
 * ...

Or maybe that doesn't matter because the rest of EqualsBuilder will be unhappy anyway.

> Javadoc Example for EqualsBuilder is questionable
> -------------------------------------------------
>
>                 Key: LANG-353
>                 URL: https://issues.apache.org/jira/browse/LANG-353
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Christoph Kutzinski
>            Priority: Minor
>             Fix For: 2.4
>
>
> The Javadoc example for the class EqualsBuilder ist questionable:
>  public boolean equals(Object obj) {
>    if (obj instanceof MyClass == false) {
>      return false;
>    }
>   ...
> The implementation with instanceof lacks guarantees like equals-symmetry  (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm  for a discussion of the issue)
> The example should be changed to use getClass(). Attention: the solution in the link above is incomplete as it doesn't check for null

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


[jira] Updated: (LANG-353) Javadoc Example for EqualsBuilder is questionable

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-353?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-353:
-------------------------------

    Fix Version/s: 2.4

> Javadoc Example for EqualsBuilder is questionable
> -------------------------------------------------
>
>                 Key: LANG-353
>                 URL: https://issues.apache.org/jira/browse/LANG-353
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Christoph Kutzinski
>            Priority: Minor
>             Fix For: 2.4
>
>
> The Javadoc example for the class EqualsBuilder ist questionable:
>  public boolean equals(Object obj) {
>    if (obj instanceof MyClass == false) {
>      return false;
>    }
>   ...
> The implementation with instanceof lacks guarantees like equals-symmetry  (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm  for a discussion of the issue)
> The example should be changed to use getClass(). Attention: the solution in the link above is incomplete as it doesn't check for null

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