6896157: unsynchronized hashmap in com.sun.corba.se.impl.transport.SelectorImpl.createReaderThread
authorskoppar
Thu, 07 Oct 2010 00:51:42 -0700
changeset 7581 26d1bb99615f
parent 7580 4b09cf866b32
child 7582 f7528916cb2d
6896157: unsynchronized hashmap in com.sun.corba.se.impl.transport.SelectorImpl.createReaderThread Reviewed-by: asaha
corba/src/share/classes/com/sun/corba/se/impl/transport/SelectorImpl.java
--- a/corba/src/share/classes/com/sun/corba/se/impl/transport/SelectorImpl.java	Thu Oct 07 00:49:05 2010 -0700
+++ b/corba/src/share/classes/com/sun/corba/se/impl/transport/SelectorImpl.java	Thu Oct 07 00:51:42 2010 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,7 @@
 import java.nio.channels.Selector;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Map;
 import java.util.Iterator;
 import java.util.List;
 
@@ -66,7 +67,7 @@
     private List deferredRegistrations;
     private List interestOpsList;
     private HashMap listenerThreads;
-    private HashMap readerThreads;
+    private Map readerThreads;
     private boolean selectorStarted;
     private boolean closed;
     private ORBUtilSystemException wrapper ;
@@ -81,7 +82,7 @@
         deferredRegistrations = new ArrayList();
         interestOpsList = new ArrayList();
         listenerThreads = new HashMap();
-        readerThreads = new HashMap();
+        readerThreads = java.util.Collections.synchronizedMap(new HashMap());
         closed = false;
         wrapper = ORBUtilSystemException.get(orb,CORBALogDomains.RPC_TRANSPORT);
     }
@@ -178,8 +179,13 @@
         }
 
         if (eventHandler.shouldUseSelectThreadToWait()) {
-            SelectionKey selectionKey = eventHandler.getSelectionKey();
-            selectionKey.cancel();
+            SelectionKey selectionKey ;
+            synchronized(deferredRegistrations) {
+                selectionKey = eventHandler.getSelectionKey();
+            }
+            if (selectionKey != null) {
+                selectionKey.cancel();
+            }
             selector.wakeup();
             return;
         }