Author: sandymac
Date: Sat Oct 28 22:20:38 2006
New Revision: 468834

URL: http://svn.apache.org/viewvc?view=rev&rev=468834
Log:
Make sure the natural ordering is consistent with equals, 
see java.lang.Comparable Javadocs, 
fixes POOL-85 as reported by Mike Martin.
Added checks in case the long to int cast overflows.

Modified:
    
jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java

Modified: 
jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java?view=diff&rev=468834&r1=468833&r2=468834
==============================================================================
--- 
jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
 (original)
+++ 
jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
 Sat Oct 28 22:20:38 2006
@@ -1451,7 +1451,15 @@
         }
 
         public int compareTo(ObjectTimestampPair other) {
-            return (int) (this.tstamp - other.tstamp);
+            final long tstampdiff = this.tstamp - other.tstamp;
+            if (tstampdiff == 0) {
+                // make sure the natural ordering is consistent with equals
+                // see java.lang.Comparable Javadocs
+                return System.identityHashCode(this) - 
System.identityHashCode(other);
+            } else {
+                // handle int overflow
+                return (int)Math.min(Math.max(tstampdiff, Integer.MIN_VALUE), 
Integer.MAX_VALUE);
+            }
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to