Author: sebb
Date: Fri Apr 17 13:44:46 2009
New Revision: 766003
URL: http://svn.apache.org/viewvc?rev=766003&view=rev
Log:
MATH-259 - throw IllegalArgument rather than ClassCast to better retain
original behaviour
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/stat/Frequency.java
commons/proper/math/trunk/src/test/org/apache/commons/math/stat/FrequencyTest.java
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/stat/Frequency.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/Frequency.java?rev=766003&r1=766002&r2=766003&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/stat/Frequency.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/stat/Frequency.java
Fri Apr 17 13:44:46 2009
@@ -101,13 +101,17 @@
* </p>
*
* @param v the value to add.
- * @throws IllegalArgumentException if <code>v</code> is not comparable
with previous entries
- * @throws ClassCastException if <code>v</code> is not Comparable
+ * @throws IllegalArgumentException if <code>v</code> is not Comparable,
+ * or is not comparable with previous entries
* @deprecated use {...@link #addValue(Comparable)} instead
*/
@Deprecated
public void addValue(Object v) {
- addValue((Comparable<?>) v);
+ if (v instanceof Comparable<?>){
+ addValue((Comparable<?>) v);
+ } else {
+ throw new IllegalArgumentException("Object must implement
Comparable");
+ }
}
/**
Modified:
commons/proper/math/trunk/src/test/org/apache/commons/math/stat/FrequencyTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/FrequencyTest.java?rev=766003&r1=766002&r2=766003&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/org/apache/commons/math/stat/FrequencyTest.java
(original)
+++
commons/proper/math/trunk/src/test/org/apache/commons/math/stat/FrequencyTest.java
Fri Apr 17 13:44:46 2009
@@ -192,16 +192,16 @@
// Check what happens when non-Comparable objects are added
public void testAddNonComparable(){
try {
- f.addValue(new Object()); // This was OK
- fail("Expected ClassCastException");
- } catch (ClassCastException expected) {
+ f.addValue(new Object()); // This was previously OK
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
}
f.clear();
f.addValue(1);
try {
f.addValue(new Object());
- fail("Expected ClassCastException"); // Previously would have been
IllegalArgument
- } catch (ClassCastException expected) {
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
}
}