commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benno Markiewicz (JIRA)" <>
Subject [jira] Created: (LANG-394) Equalsbuilder fails at using unmodifiable collection
Date Thu, 03 Jan 2008 14:42:34 GMT
Equalsbuilder fails at using unmodifiable collection

                 Key: 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

  public void testInEqualsBuilder() {
    class Foo {
      private final Collection<String> list;

      public Foo() {
        this.list = new ArrayList<String>();


      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();

    // 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.

View raw message