src/share/classes/sun/applet/AppletPanel.java
Print this page
rev 10175 : 8042872: Fix raw and unchecked warnings in sun.applet
Reviewed-by:
*** 177,187 ****
ThreadGroup appletGroup = loader.getThreadGroup();
handler = new Thread(appletGroup, this, "thread " + nm);
// set the context class loader for this thread
! AccessController.doPrivileged(new PrivilegedAction() {
@Override
public Object run() {
handler.setContextClassLoader(loader);
return null;
}
--- 177,187 ----
ThreadGroup appletGroup = loader.getThreadGroup();
handler = new Thread(appletGroup, this, "thread " + nm);
// set the context class loader for this thread
! AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
handler.setContextClassLoader(loader);
return null;
}
*** 251,261 ****
private AppletListener listeners;
/**
* AppletEvent Queue
*/
! private Queue queue = null;
synchronized public void addAppletListener(AppletListener l) {
listeners = AppletEventMulticaster.add(listeners, l);
}
--- 251,261 ----
private AppletListener listeners;
/**
* AppletEvent Queue
*/
! private Queue<Integer> queue = null;
synchronized public void addAppletListener(AppletListener l) {
listeners = AppletEventMulticaster.add(listeners, l);
}
*** 280,290 ****
*/
public void sendEvent(int id) {
synchronized(this) {
if (queue == null) {
//System.out.println("SEND0= " + id);
! queue = new Queue();
}
Integer eventId = Integer.valueOf(id);
queue.enqueue(eventId);
notifyAll();
}
--- 280,290 ----
*/
public void sendEvent(int id) {
synchronized(this) {
if (queue == null) {
//System.out.println("SEND0= " + id);
! queue = new Queue<>();
}
Integer eventId = Integer.valueOf(id);
queue.enqueue(eventId);
notifyAll();
}
*** 307,317 ****
*/
synchronized AppletEvent getNextEvent() throws InterruptedException {
while (queue == null || queue.isEmpty()) {
wait();
}
! Integer eventId = (Integer)queue.dequeue();
return new AppletEvent(this, eventId.intValue(), null);
}
boolean emptyEventQueue() {
if ((queue == null) || (queue.isEmpty()))
--- 307,317 ----
*/
synchronized AppletEvent getNextEvent() throws InterruptedException {
while (queue == null || queue.isEmpty()) {
wait();
}
! Integer eventId = queue.dequeue();
return new AppletEvent(this, eventId.intValue(), null);
}
boolean emptyEventQueue() {
if ((queue == null) || (queue.isEmpty()))
*** 629,646 ****
* It does that without calling Window.getMostRecentFocusOwner since it
* provides its own logic contradicting with setDefautlFocus. Instead, it
* calls KeyboardFocusManager directly.
*/
private Component getMostRecentFocusOwnerForWindow(Window w) {
! Method meth = (Method)AccessController.doPrivileged(new PrivilegedAction() {
@Override
! public Object run() {
Method meth = null;
try {
meth = KeyboardFocusManager.class.getDeclaredMethod(
"getMostRecentFocusOwner",
! new Class[]{Window.class});
meth.setAccessible(true);
} catch (Exception e) {
// Must never happen
e.printStackTrace();
}
--- 629,647 ----
* It does that without calling Window.getMostRecentFocusOwner since it
* provides its own logic contradicting with setDefautlFocus. Instead, it
* calls KeyboardFocusManager directly.
*/
private Component getMostRecentFocusOwnerForWindow(Window w) {
! Method meth = AccessController.doPrivileged(
! new PrivilegedAction<Method>() {
@Override
! public Method run() {
Method meth = null;
try {
meth = KeyboardFocusManager.class.getDeclaredMethod(
"getMostRecentFocusOwner",
! new Class<?>[]{Window.class});
meth.setAccessible(true);
} catch (Exception e) {
// Must never happen
e.printStackTrace();
}
*** 986,996 ****
}
/**
* The class loaders
*/
! private static HashMap classloaders = new HashMap();
/**
* Flush a class loader.
*/
public static synchronized void flushClassLoader(String key) {
--- 987,997 ----
}
/**
* The class loaders
*/
! private static HashMap<String, AppletClassLoader> classloaders = new HashMap<>();
/**
* Flush a class loader.
*/
public static synchronized void flushClassLoader(String key) {
*** 999,1009 ****
/**
* Flush all class loaders.
*/
public static synchronized void flushClassLoaders() {
! classloaders = new HashMap();
}
/**
* This method actually creates an AppletClassLoader.
*
--- 1000,1010 ----
/**
* Flush all class loaders.
*/
public static synchronized void flushClassLoaders() {
! classloaders = new HashMap<>();
}
/**
* This method actually creates an AppletClassLoader.
*
*** 1016,1033 ****
/**
* Get a class loader. Create in a restricted context
*/
synchronized AppletClassLoader getClassLoader(final URL codebase, final String key) {
! AppletClassLoader c = (AppletClassLoader)classloaders.get(key);
if (c == null) {
AccessControlContext acc =
getAccessControlContext(codebase);
! c = (AppletClassLoader)
! AccessController.doPrivileged(new PrivilegedAction() {
@Override
! public Object run() {
AppletClassLoader ac = createClassLoader(codebase);
/* Should the creation of the classloader be
* within the class synchronized block? Since
* this class is used by the plugin, take care
* to avoid deadlocks, or specialize
--- 1017,1034 ----
/**
* Get a class loader. Create in a restricted context
*/
synchronized AppletClassLoader getClassLoader(final URL codebase, final String key) {
! AppletClassLoader c = classloaders.get(key);
if (c == null) {
AccessControlContext acc =
getAccessControlContext(codebase);
! c = AccessController.doPrivileged(
! new PrivilegedAction<AppletClassLoader>() {
@Override
! public AppletClassLoader run() {
AppletClassLoader ac = createClassLoader(codebase);
/* Should the creation of the classloader be
* within the class synchronized block? Since
* this class is used by the plugin, take care
* to avoid deadlocks, or specialize
*** 1041,1052 ****
* the applet cannot process other messages,
* particularly messages such as destroy
* (which timeout when called from the browser).
*/
synchronized (getClass()) {
! AppletClassLoader res =
! (AppletClassLoader)classloaders.get(key);
if (res == null) {
classloaders.put(key, ac);
return ac;
} else {
return res;
--- 1042,1052 ----
* the applet cannot process other messages,
* particularly messages such as destroy
* (which timeout when called from the browser).
*/
synchronized (getClass()) {
! AppletClassLoader res = classloaders.get(key);
if (res == null) {
classloaders.put(key, ac);
return ac;
} else {
return res;
*** 1064,1077 ****
* connnect to the codebase, and whatever else the policy grants
* to all codebases.
*/
private AccessControlContext getAccessControlContext(final URL codebase) {
! PermissionCollection perms = (PermissionCollection)
! AccessController.doPrivileged(new PrivilegedAction() {
@Override
! public Object run() {
Policy p = java.security.Policy.getPolicy();
if (p != null) {
return p.getPermissions(new CodeSource(null,
(java.security.cert.Certificate[]) null));
} else {
--- 1064,1077 ----
* connnect to the codebase, and whatever else the policy grants
* to all codebases.
*/
private AccessControlContext getAccessControlContext(final URL codebase) {
! PermissionCollection perms = AccessController.doPrivileged(
! new PrivilegedAction<PermissionCollection>() {
@Override
! public PermissionCollection run() {
Policy p = java.security.Policy.getPolicy();
if (p != null) {
return p.getPermissions(new CodeSource(null,
(java.security.cert.Certificate[]) null));
} else {
*** 1170,1186 ****
// Synchronization on Window.class is needed for locking the
// critical section of the window list in AppContext.
synchronized (Window.class)
{
! WeakReference weakRef = null;
// Remove frame from the Window list in wrong AppContext
{
// Lookup current frame's AppContext
! Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)oldAppContext.get(Window.class);
if (windowList != null) {
! for (WeakReference ref : windowList) {
if (ref.get() == frame) {
weakRef = ref;
break;
}
}
--- 1170,1188 ----
// Synchronization on Window.class is needed for locking the
// critical section of the window list in AppContext.
synchronized (Window.class)
{
! WeakReference<Window> weakRef = null;
// Remove frame from the Window list in wrong AppContext
{
// Lookup current frame's AppContext
! @SuppressWarnings("unchecked")
! Vector<WeakReference<Window>> windowList =
! (Vector<WeakReference<Window>>)oldAppContext.get(Window.class);
if (windowList != null) {
! for (WeakReference<Window> ref : windowList) {
if (ref.get() == frame) {
weakRef = ref;
break;
}
}
*** 1193,1203 ****
// Put the frame into the applet's AppContext map
SunToolkit.insertTargetMapping(frame, newAppContext);
// Insert frame into the Window list in the applet's AppContext map
{
! Vector<WeakReference<Window>> windowList = (Vector)newAppContext.get(Window.class);
if (windowList == null) {
windowList = new Vector<WeakReference<Window>>();
newAppContext.put(Window.class, windowList);
}
// use the same weakRef here as it is used elsewhere
--- 1195,1207 ----
// Put the frame into the applet's AppContext map
SunToolkit.insertTargetMapping(frame, newAppContext);
// Insert frame into the Window list in the applet's AppContext map
{
! @SuppressWarnings("unchecked")
! Vector<WeakReference<Window>> windowList =
! (Vector<WeakReference<Window>>)newAppContext.get(Window.class);
if (windowList == null) {
windowList = new Vector<WeakReference<Window>>();
newAppContext.put(Window.class, windowList);
}
// use the same weakRef here as it is used elsewhere
*** 1222,1232 ****
// of the applet class file.
// synchronized on applet class object, so calling from
// different instances of the same applet will be
// serialized.
! Class appletClass = applet.getClass();
synchronized(appletClass) {
// Determine if the JDK level of an applet has been
// checked before.
Boolean jdk11Target = loader.isJDK11Target(appletClass);
--- 1226,1236 ----
// of the applet class file.
// synchronized on applet class object, so calling from
// different instances of the same applet will be
// serialized.
! Class<?> appletClass = applet.getClass();
synchronized(appletClass) {
// Determine if the JDK level of an applet has been
// checked before.
Boolean jdk11Target = loader.isJDK11Target(appletClass);