src/share/classes/sun/applet/AppletPanel.java
Print this page
rev 10175 : 8042872: Fix raw and unchecked warnings in sun.applet
Reviewed-by:
@@ -177,11 +177,11 @@
ThreadGroup appletGroup = loader.getThreadGroup();
handler = new Thread(appletGroup, this, "thread " + nm);
// set the context class loader for this thread
- AccessController.doPrivileged(new PrivilegedAction() {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
handler.setContextClassLoader(loader);
return null;
}
@@ -251,11 +251,11 @@
private AppletListener listeners;
/**
* AppletEvent Queue
*/
- private Queue queue = null;
+ private Queue<Integer> queue = null;
synchronized public void addAppletListener(AppletListener l) {
listeners = AppletEventMulticaster.add(listeners, l);
}
@@ -280,11 +280,11 @@
*/
public void sendEvent(int id) {
synchronized(this) {
if (queue == null) {
//System.out.println("SEND0= " + id);
- queue = new Queue();
+ queue = new Queue<>();
}
Integer eventId = Integer.valueOf(id);
queue.enqueue(eventId);
notifyAll();
}
@@ -307,11 +307,11 @@
*/
synchronized AppletEvent getNextEvent() throws InterruptedException {
while (queue == null || queue.isEmpty()) {
wait();
}
- Integer eventId = (Integer)queue.dequeue();
+ Integer eventId = queue.dequeue();
return new AppletEvent(this, eventId.intValue(), null);
}
boolean emptyEventQueue() {
if ((queue == null) || (queue.isEmpty()))
@@ -629,18 +629,19 @@
* 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() {
+ Method meth = AccessController.doPrivileged(
+ new PrivilegedAction<Method>() {
@Override
- public Object run() {
+ public Method run() {
Method meth = null;
try {
meth = KeyboardFocusManager.class.getDeclaredMethod(
"getMostRecentFocusOwner",
- new Class[]{Window.class});
+ new Class<?>[]{Window.class});
meth.setAccessible(true);
} catch (Exception e) {
// Must never happen
e.printStackTrace();
}
@@ -986,11 +987,11 @@
}
/**
* The class loaders
*/
- private static HashMap classloaders = new HashMap();
+ private static HashMap<String, AppletClassLoader> classloaders = new HashMap<>();
/**
* Flush a class loader.
*/
public static synchronized void flushClassLoader(String key) {
@@ -999,11 +1000,11 @@
/**
* Flush all class loaders.
*/
public static synchronized void flushClassLoaders() {
- classloaders = new HashMap();
+ classloaders = new HashMap<>();
}
/**
* This method actually creates an AppletClassLoader.
*
@@ -1016,18 +1017,18 @@
/**
* Get a class loader. Create in a restricted context
*/
synchronized AppletClassLoader getClassLoader(final URL codebase, final String key) {
- AppletClassLoader c = (AppletClassLoader)classloaders.get(key);
+ AppletClassLoader c = classloaders.get(key);
if (c == null) {
AccessControlContext acc =
getAccessControlContext(codebase);
- c = (AppletClassLoader)
- AccessController.doPrivileged(new PrivilegedAction() {
+ c = AccessController.doPrivileged(
+ new PrivilegedAction<AppletClassLoader>() {
@Override
- public Object run() {
+ 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,12 +1042,11 @@
* 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);
+ AppletClassLoader res = classloaders.get(key);
if (res == null) {
classloaders.put(key, ac);
return ac;
} else {
return res;
@@ -1064,14 +1064,14 @@
* 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() {
+ PermissionCollection perms = AccessController.doPrivileged(
+ new PrivilegedAction<PermissionCollection>() {
@Override
- public Object run() {
+ 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,17 +1170,19 @@
// Synchronization on Window.class is needed for locking the
// critical section of the window list in AppContext.
synchronized (Window.class)
{
- WeakReference weakRef = null;
+ WeakReference<Window> 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);
+ @SuppressWarnings("unchecked")
+ Vector<WeakReference<Window>> windowList =
+ (Vector<WeakReference<Window>>)oldAppContext.get(Window.class);
if (windowList != null) {
- for (WeakReference ref : windowList) {
+ for (WeakReference<Window> ref : windowList) {
if (ref.get() == frame) {
weakRef = ref;
break;
}
}
@@ -1193,11 +1195,13 @@
// 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);
+ @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,11 +1226,11 @@
// 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();
+ Class<?> appletClass = applet.getClass();
synchronized(appletClass) {
// Determine if the JDK level of an applet has been
// checked before.
Boolean jdk11Target = loader.isJDK11Target(appletClass);