jmcnally 2002/07/30 19:04:22
Modified: src/java/org/apache/torque/om NumberKey.java
src/test/org/apache/torque/om NumberKeyTest.java
Log:
should not go immediately to an equals method that strictly obeys the symmetry
rule. It reverses previous behavior, so an exception is warranted.
Revision Changes Path
1.11 +10 -1
jakarta-turbine-torque/src/java/org/apache/torque/om/NumberKey.java
Index: NumberKey.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/om/NumberKey.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- NumberKey.java 26 Jul 2002 22:30:35 -0000 1.10
+++ NumberKey.java 31 Jul 2002 02:04:21 -0000 1.11
@@ -168,6 +168,15 @@
if (!(keyObj instanceof NumberKey))
{
+ // NumberKeys used to be comparable to Strings. This behavior has
+ // been changed, I don't think it is a good idea to fail silently
+ // as code may be dependent on the old behavior.
+ if (keyObj instanceof String)
+ {
+ throw new IllegalArgumentException(
+ "NumberKeys are not comparable to Strings");
+ }
+
return false;
}
1.2 +14 -4
jakarta-turbine-torque/src/test/org/apache/torque/om/NumberKeyTest.java
Index: NumberKeyTest.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/test/org/apache/torque/om/NumberKeyTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NumberKeyTest.java 25 Jul 2002 07:28:16 -0000 1.1
+++ NumberKeyTest.java 31 Jul 2002 02:04:22 -0000 1.2
@@ -94,8 +94,18 @@
Assert.assertTrue(n1b.equals(n1a));
Assert.assertTrue(!"1".equals(n1a));
- Assert.assertTrue(!n1a.equals("1"));
-
+ // As this used to give false, i.e. n1a was considered equal to "1"
+ // it can lead to difficult to find bugs if it is immediately
+ // changed to the opposite. So this will throw an exception.
+ //Assert.assertTrue(!n1a.equals("1"));
+ try
+ {
+ Assert.assertTrue(!n1a.equals("1"));
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
Assert.assertTrue(!n1a.equals(new Integer(1)));
Assert.assertTrue(!new Integer(1).equals(n1a));
}
@@ -122,4 +132,4 @@
Assert.assertEquals(n2a, array[2]);
}
-}
\ No newline at end of file
+}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>