From 12a09d26929a3a7bfb46e55ed3e3641ff3e86292 Mon Sep 17 00:00:00 2001 From: Denis Lila Date: Wed, 13 Apr 2011 12:18:38 -0400 Subject: Fix some concurrency problems in PluginAppletViewer.java. --- .../java/sun/applet/PluginAppletViewer.java | 61 +++++++++++++--------- 1 file changed, 35 insertions(+), 26 deletions(-) (limited to 'plugin/icedteanp/java/sun/applet') diff --git a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java index 9099524..37e20d3 100644 --- a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java +++ b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java @@ -103,6 +103,8 @@ import java.util.Iterator; 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 @@ public class PluginAppletViewer extends XEmbeddedFrame new HashMap(); // Instance identifier -> PluginAppletViewer object. - private static HashMap applets = - new HashMap(); + private static ConcurrentMap applets = + new ConcurrentHashMap(); private static PluginStreamHandler streamhandler; private static PluginCallRequestFactory requestFactory; - private static HashMap status = - new HashMap(); + private static ConcurrentMap status = + new ConcurrentHashMap(); private long handle = 0; private WindowListener windowEventListener = null; @@ -401,8 +403,10 @@ public class PluginAppletViewer extends XEmbeddedFrame 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 @@ public class PluginAppletViewer extends XEmbeddedFrame 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 @@ public class PluginAppletViewer extends XEmbeddedFrame imageRefs.clear(); } - static Vector appletPanels = new Vector(); + private static Vector appletPanels = new Vector(); /** * Get an applet by name. @@ -904,20 +909,22 @@ public class PluginAppletViewer extends XEmbeddedFrame 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 @@ public class PluginAppletViewer extends XEmbeddedFrame SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect"); - for (Enumeration e = appletPanels.elements(); e.hasMoreElements();) { - AppletPanel p = e.nextElement(); - if (p.getDocumentBase().equals(panel.getDocumentBase())) { + synchronized(appletPanels) { + for (Enumeration 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); + } } } } -- cgit v1.2.3