changeset 208:c84f2e5b039f

Fix some concurrency problems in PluginAppletViewer.java.
author Denis Lila <dlila@redhat.com>
date Wed, 13 Apr 2011 12:18:38 -0400
parents 934543b8084d
children 1e661bc821f8
files ChangeLog plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
diffstat 2 files changed, 45 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Apr 11 16:03:44 2011 +0100
+++ b/ChangeLog	Wed Apr 13 12:18:38 2011 -0400
@@ -1,3 +1,13 @@
+2011-04-12  Denis Lila  <dlila@redhat.com>
+
+	* plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
+	(applets, status): Make concurrent.
+	(PluginAppletViewer): Synchronize appletPanels addElement.
+	(destroyApplet): Remove applets.containsKey because it and the
+	get that followed it were not atomic.
+	(appletPanels): Privatize.
+	(getApplet, getApplets): Synchronize iteration.
+
 2011-04-08  Omair Majid  <omajid@redhat.com>
 
 	* README: Update to add notes on rhino and junit.
--- a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java	Mon Apr 11 16:03:44 2011 +0100
+++ b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java	Wed Apr 13 12:18:38 2011 -0400
@@ -103,6 +103,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Vector;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import javax.swing.SwingUtilities;
 
@@ -340,15 +342,15 @@
             new HashMap<Integer, PluginParseRequest>();
 
     // Instance identifier -> PluginAppletViewer object.
-    private static HashMap<Integer, PluginAppletViewer> applets =
-            new HashMap<Integer, PluginAppletViewer>();
+    private static ConcurrentMap<Integer, PluginAppletViewer> applets =
+            new ConcurrentHashMap<Integer, PluginAppletViewer>();
 
     private static PluginStreamHandler streamhandler;
 
     private static PluginCallRequestFactory requestFactory;
 
-    private static HashMap<Integer, PAV_INIT_STATUS> status =
-            new HashMap<Integer, PAV_INIT_STATUS>();
+    private static ConcurrentMap<Integer, PAV_INIT_STATUS> status =
+            new ConcurrentHashMap<Integer, PAV_INIT_STATUS>();
 
     private long handle = 0;
     private WindowListener windowEventListener = null;
@@ -401,8 +403,10 @@
         this.identifier = identifier;
         this.panel = appletPanel;
 
-        if (!appletPanels.contains(panel))
-            appletPanels.addElement(panel);
+        synchronized(appletPanels) {
+            if (!appletPanels.contains(panel))
+                appletPanels.addElement(panel);
+        }
 
         windowEventListener = new WindowAdapter() {
 
@@ -656,8 +660,9 @@
         PluginDebug.debug("Attempting to destroy frame ", identifier);
 
         // Try to dispose the panel right away
-        if (applets.containsKey(identifier))
-            applets.get(identifier).dispose();
+        PluginAppletViewer pav = applets.get(identifier);
+        if (pav != null)
+            pav.dispose();
 
         // If panel is already disposed, return
         if (applets.get(identifier).panel.applet == null) {
@@ -895,7 +900,7 @@
         imageRefs.clear();
     }
 
-    static Vector<AppletPanel> appletPanels = new Vector<AppletPanel>();
+    private static Vector<AppletPanel> appletPanels = new Vector<AppletPanel>();
 
     /**
      * Get an applet by name.
@@ -904,20 +909,22 @@
         name = name.toLowerCase();
         SocketPermission panelSp =
                 new SocketPermission(panel.getCodeBase().getHost(), "connect");
-        for (Enumeration e = appletPanels.elements(); e.hasMoreElements();) {
-            AppletPanel p = (AppletPanel) e.nextElement();
-            String param = p.getParameter("name");
-            if (param != null) {
-                param = param.toLowerCase();
-            }
-            if (name.equals(param) &&
-                    p.getDocumentBase().equals(panel.getDocumentBase())) {
+        synchronized(appletPanels) {
+            for (Enumeration e = appletPanels.elements(); e.hasMoreElements();) {
+                AppletPanel p = (AppletPanel) e.nextElement();
+                String param = p.getParameter("name");
+                if (param != null) {
+                    param = param.toLowerCase();
+                }
+                if (name.equals(param) &&
+                        p.getDocumentBase().equals(panel.getDocumentBase())) {
 
-                SocketPermission sp =
+                    SocketPermission sp =
                         new SocketPermission(p.getCodeBase().getHost(), "connect");
 
-                if (panelSp.implies(sp)) {
-                    return p.applet;
+                    if (panelSp.implies(sp)) {
+                        return p.applet;
+                    }
                 }
             }
         }
@@ -933,14 +940,16 @@
         SocketPermission panelSp =
                 new SocketPermission(panel.getCodeBase().getHost(), "connect");
 
-        for (Enumeration<AppletPanel> e = appletPanels.elements(); e.hasMoreElements();) {
-            AppletPanel p = e.nextElement();
-            if (p.getDocumentBase().equals(panel.getDocumentBase())) {
+        synchronized(appletPanels) {
+            for (Enumeration<AppletPanel> e = appletPanels.elements(); e.hasMoreElements();) {
+                AppletPanel p = e.nextElement();
+                if (p.getDocumentBase().equals(panel.getDocumentBase())) {
 
-                SocketPermission sp =
+                    SocketPermission sp =
                         new SocketPermission(p.getCodeBase().getHost(), "connect");
-                if (panelSp.implies(sp)) {
-                    v.addElement(p.applet);
+                    if (panelSp.implies(sp)) {
+                        v.addElement(p.applet);
+                    }
                 }
             }
         }