commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Closed: (LANG-394) Equalsbuilder fails at using unmodifiable collection
Date Sat, 05 Jan 2008 06:26:34 GMT

     [ https://issues.apache.org/jira/browse/LANG-394?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Henri Yandell closed LANG-394.
------------------------------

    Resolution: Invalid

Many thanks for that explanation Julien, the javadoc definitely backs up what you're saying
and so I'm closing this issue.

> Equalsbuilder fails at using unmodifiable collection
> ----------------------------------------------------
>
>                 Key: LANG-394
>                 URL: https://issues.apache.org/jira/browse/LANG-394
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.3
>         Environment: Win XP SP2, JRE 1.5.0_12
>            Reporter: Benno Markiewicz
>
> When using the equalsbuilder to build a equals-method it comes to failures, when comparing
object which have unmodifiable list properties.
> Look at the simplified example. A class Foo with a collection (A,B,C) is build up. The
equals method uses the equalsbuilder to append the list to it. The getter of the list returns
a unmodifiable collection. This situation leads to the test failure. Without capsulation in
a unmodifiable collection the test succeeds. What's wrong? I want to compare such objects
by value not by reference.
>  @Test
>   public void testInEqualsBuilder() {
>     class Foo {
>       private final Collection<String> list;
>       public Foo() {
>         this.list = new ArrayList<String>();
>         this.list.add("A");
>         this.list.add("B");
>         this.list.add("C");
>       }
>       @Override
>       public boolean equals(final Object object) {
>         if (object == this) {
>           return true;
>         }
>         if (!(object instanceof Foo)) {
>           return false;
>         }
>         final Foo rhs = (Foo) object;
>         
>         final EqualsBuilder eb = new EqualsBuilder();
>         eb.append(this.list, rhs.getList());
>         return eb.isEquals();
>       }
>       private Collection<String> getList() {
>          return Collections.unmodifiableCollection(this.list);
>        }
>     }
>     final Foo x = new Foo();
>     assertTrue(x.equals(x));
>    
>     // FAILURE list [A,B,C] is not equal to list [A,B,C], when using
>     // unmodifiableCollection?
>     assertTrue(x.equals(new Foo()));
>   }

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


Mime
View raw message