commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Wilson <andrew.wil...@db.com>
Subject Threading bug in Commons Lang?
Date Fri, 12 Sep 2008 15:41:47 GMT
Hiya,

 

I've been tracking down a bug, which may be a usage issue, but seems like
a bug in HashCodeBuilder.reflectionHashCode

 

If you run the code below with 1 thread it runs fine.  However, if you run
it with (say) 100 you start getting lots of "Ow!".  

 

Any thoughts, many thanks,

Andrew.

 

Try the following code :

 

import org.apache.commons.lang.builder.EqualsBuilder;

import org.apache.commons.lang.builder.HashCodeBuilder;

 

public class MyTest implements Runnable {

 

    private MyTest() {

        for(int i=0;i<100;i++) {

            new Thread(this).start();

        }

    }

 

    public static void main(String[] args) {

        new MyTest();

    }

 

    public void run() {

        for(int i=0;i<100000;i++) {

 

            if(new MyClass1("aaa").hashCode() != new
MyClass1("aaa").hashCode()) {

                System.out.println("Ow ! ");

            } 

        }

    }

    private static class MyClass1 {

 

        private MyClass2 myClass2;

 

        public MyClass1(String arg) {

            myClass2 = new MyClass2(arg);

        }

 

        public boolean equals(Object o) {

            return EqualsBuilder.reflectionEquals(o, this);

        }

 

        public int hashCode() {

            return HashCodeBuilder.reflectionHashCode(this);

        }

    }

 

    public static class MyClass2 {

        public String arg;

 

        public MyClass2(String arg) {

            this.arg = arg;

        }

 

        public boolean equals(Object o) {

            return EqualsBuilder.reflectionEquals(o, this);

        }

 

        public int hashCode() {

            return HashCodeBuilder.reflectionHashCode(this);

        }

    }

}



---

This e-mail may contain confidential and/or privileged information. If you are not the intended
recipient (or have received this e-mail in error) please notify the sender immediately and
delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in
this e-mail is strictly forbidden.

Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate
and regulatory disclosures.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message