db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r790218 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/TopService.java
Date Wed, 01 Jul 2009 15:28:18 GMT
Author: kahatlen
Date: Wed Jul  1 15:28:13 2009
New Revision: 790218

URL: http://svn.apache.org/viewvc?rev=790218&view=rev
Log:
DERBY-4018: ArrayIndexOutOfBoundsException in TopService.inService under heavy multithreaded
use of EmbeddedDriver

Closed another unsynchronized window between Vector.size() and
Vector.elementAt().

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/TopService.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/TopService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/TopService.java?rev=790218&r1=790217&r2=790218&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/TopService.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/TopService.java
Wed Jul  1 15:28:13 2009
@@ -229,6 +229,9 @@
      * was found
      */
     private ModuleInstance findModuleInstance(Object instance) {
+        // DERBY-4018: Need to hold the synchronization over the entire loop
+        // to prevent concurrent modifications from causing an
+        // ArrayIndexOutOfBoundsException.
         synchronized (moduleInstances) {
             for (int i = 0; i < moduleInstances.size(); i++) {
                 ModuleInstance module = (ModuleInstance) moduleInstances.get(i);
@@ -269,8 +272,20 @@
 		// see if a running implementation will handle this protocol
 		synchronized (this) {
 
-			for (int i = 0; i < moduleInstances.size(); i++) {
-				ModuleInstance module = (ModuleInstance) moduleInstances.elementAt(i);
+            for (int i = 0;; i++) {
+                final ModuleInstance module;
+
+                // DERBY-4018: Synchronized block in order to close the window
+                // between size() and elementAt() where the size may change
+                // and result in an ArrayIndexOutOfBoundsException.
+                synchronized (moduleInstances) {
+                    if (i < moduleInstances.size()) {
+                        module = (ModuleInstance) moduleInstances.elementAt(i);
+                    } else {
+                        // No more instances to look at, break out of the loop.
+                        break;
+                    }
+                }
 
                 // DERBY-2074: The module has not been properly booted, so we
                 // cannot yet determine whether or not this is a module we can



Mime
View raw message