[hornetq-commits] JBoss hornetq SVN: r12181 - trunk/hornetq-journal/src/main/java/org/hornetq/core/asyncio/impl.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Feb 23 09:18:39 EST 2012


Author: borges
Date: 2012-02-23 09:18:38 -0500 (Thu, 23 Feb 2012)
New Revision: 12181

Modified:
   trunk/hornetq-journal/src/main/java/org/hornetq/core/asyncio/impl/AsynchronousFileImpl.java
Log:
Fix risk of problems should someone call PriorityQueue.remove(o) using CallbackHolder.

Modified: trunk/hornetq-journal/src/main/java/org/hornetq/core/asyncio/impl/AsynchronousFileImpl.java
===================================================================
--- trunk/hornetq-journal/src/main/java/org/hornetq/core/asyncio/impl/AsynchronousFileImpl.java	2012-02-23 14:18:22 UTC (rev 12180)
+++ trunk/hornetq-journal/src/main/java/org/hornetq/core/asyncio/impl/AsynchronousFileImpl.java	2012-02-23 14:18:38 UTC (rev 12181)
@@ -711,6 +711,14 @@
 
    // Inner classes ---------------------------------------------------------------------
 
+   /**
+    * Explicitly adding a compare to clause that returns 0 for at least the same object.
+    * <p>
+    * If {@link Comparable#compareTo(Object)} does not return 0 -for at least the same object- some
+    * Collection classes methods will fail (example {@link PriorityQueue#remove(Object)}. If it
+    * returns 0, then {@link #equals(Object)} must return {@code true} for the exact same cases,
+    * otherwise we will get compatibility problems between Java5 and Java6.
+    */
    private static class CallbackHolder implements Comparable<CallbackHolder>
    {
       final long sequence;
@@ -731,6 +739,8 @@
       public int compareTo(final CallbackHolder o)
       {
          // It shouldn't be equals in any case
+         if (this == o)
+            return 0;
          if (sequence <= o.sequence)
          {
             return -1;
@@ -740,9 +750,27 @@
             return 1;
          }
       }
+
+      /**
+       * See {@link CallbackHolder}.
+       */
+      @Override
+      public int hashCode()
+      {
+         return super.hashCode();
+      }
+
+      /**
+       * See {@link CallbackHolder}.
+       */
+      @Override
+      public boolean equals(Object obj)
+      {
+         return super.equals(obj);
+      }
    }
 
-   private static class ErrorCallback extends CallbackHolder
+   private static final class ErrorCallback extends CallbackHolder
    {
       final int errorCode;
 



More information about the hornetq-commits mailing list