FULL PRODUCT VERSION :
java version "1.5.0_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b01)
Java HotSpot(TM) Client VM (build 1.5.0_09-b01), mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
EXTRA RELEVANT SYSTEM CONFIGURATION :
None needed
A DESCRIPTION OF THE PROBLEM :
A and B are both java.util.Date objects, and A.equals(B) != B.equals(A). As quoted from Object.equals.
* <li>It is <i>symmetric</i>: for any non-null reference values
* <code>x</code> and <code>y</code>, <code>x.equals(y)</code>
* should return <code>true</code> if and only if
* <code>y.equals(x)</code> returns <code>true</code>.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the JUnit Test I've included
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect this JUnit test to pass, as it should.
ACTUAL -
JUnit test failed because equals within core java classes doesn't really mean equal!!!
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.sql.Timestamp;
import java.util.Date;
import junit.framework.TestCase;
public class SanityTest extends TestCase {
public void testEqualsReallyDoesMeanEqual() throws Exception {
Date date = new Date(-62135744400000L);
POJO pojo = new POJO();
pojo.setDate(new Timestamp(-62135744400000L));
assertTrue(date.equals(pojo.getDate()));
assertTrue(pojo.getDate().equals(date));
}
private class POJO {
Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
}
---------- END SOURCE ----------
java version "1.5.0_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b01)
Java HotSpot(TM) Client VM (build 1.5.0_09-b01), mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
EXTRA RELEVANT SYSTEM CONFIGURATION :
None needed
A DESCRIPTION OF THE PROBLEM :
A and B are both java.util.Date objects, and A.equals(B) != B.equals(A). As quoted from Object.equals.
* <li>It is <i>symmetric</i>: for any non-null reference values
* <code>x</code> and <code>y</code>, <code>x.equals(y)</code>
* should return <code>true</code> if and only if
* <code>y.equals(x)</code> returns <code>true</code>.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the JUnit Test I've included
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect this JUnit test to pass, as it should.
ACTUAL -
JUnit test failed because equals within core java classes doesn't really mean equal!!!
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.sql.Timestamp;
import java.util.Date;
import junit.framework.TestCase;
public class SanityTest extends TestCase {
public void testEqualsReallyDoesMeanEqual() throws Exception {
Date date = new Date(-62135744400000L);
POJO pojo = new POJO();
pojo.setDate(new Timestamp(-62135744400000L));
assertTrue(date.equals(pojo.getDate()));
assertTrue(pojo.getDate().equals(date));
}
private class POJO {
Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-4170629 TimeStamp violates Object.hashCode contract in two ways
-
- Closed
-
- relates to
-
JDK-6587778 java.util.Date.equals() does not enforce symmetry
-
- Closed
-