8005492: Reduce number of warnings in sun/awt/* classes
authormcherkas
Wed, 16 Jan 2013 17:26:41 +0400
changeset 15318 607db339afcc
parent 15317 a5c7745e4127
child 15319 b3d5f7360aec
8005492: Reduce number of warnings in sun/awt/* classes Reviewed-by: art, anthony
jdk/src/share/classes/java/awt/Button.java
jdk/src/share/classes/java/awt/Checkbox.java
jdk/src/share/classes/java/awt/Choice.java
jdk/src/share/classes/java/awt/Component.java
jdk/src/share/classes/java/awt/Container.java
jdk/src/share/classes/java/awt/Dialog.java
jdk/src/share/classes/java/awt/Frame.java
jdk/src/share/classes/java/awt/KeyboardFocusManager.java
jdk/src/share/classes/java/awt/Scrollbar.java
jdk/src/share/classes/java/awt/TextArea.java
jdk/src/share/classes/java/awt/TextComponent.java
jdk/src/share/classes/java/awt/TextField.java
jdk/src/share/classes/java/awt/Toolkit.java
jdk/src/share/classes/java/awt/Window.java
jdk/src/share/classes/sun/awt/image/SurfaceManager.java
--- a/jdk/src/share/classes/java/awt/Button.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/Button.java	Wed Jan 16 17:26:41 2013 +0400
@@ -300,7 +300,7 @@
      * @since 1.4
      */
     public synchronized ActionListener[] getActionListeners() {
-        return (ActionListener[]) (getListeners(ActionListener.class));
+        return getListeners(ActionListener.class);
     }
 
     /**
--- a/jdk/src/share/classes/java/awt/Checkbox.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/Checkbox.java	Wed Jan 16 17:26:41 2013 +0400
@@ -470,7 +470,7 @@
      * @since 1.4
      */
     public synchronized ItemListener[] getItemListeners() {
-        return (ItemListener[]) (getListeners(ItemListener.class));
+        return getListeners(ItemListener.class);
     }
 
     /**
--- a/jdk/src/share/classes/java/awt/Choice.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/Choice.java	Wed Jan 16 17:26:41 2013 +0400
@@ -85,7 +85,7 @@
      * @see #insert(String, int)
      * @see #remove(String)
      */
-    Vector pItems;
+    Vector<String> pItems;
 
     /**
      * The index of the current choice for this <code>Choice</code>
@@ -129,7 +129,7 @@
      */
     public Choice() throws HeadlessException {
         GraphicsEnvironment.checkHeadless();
-        pItems = new Vector();
+        pItems = new Vector<>();
     }
 
     /**
@@ -191,7 +191,7 @@
      * be called on the toolkit thread.
      */
     final String getItemImpl(int index) {
-        return (String)pItems.elementAt(index);
+        return pItems.elementAt(index);
     }
 
     /**
@@ -524,7 +524,7 @@
      * @since 1.4
      */
     public synchronized ItemListener[] getItemListeners() {
-        return (ItemListener[])(getListeners(ItemListener.class));
+        return getListeners(ItemListener.class);
     }
 
     /**
--- a/jdk/src/share/classes/java/awt/Component.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/Component.java	Wed Jan 16 17:26:41 2013 +0400
@@ -7287,6 +7287,7 @@
     }
     final Set<AWTKeyStroke> getFocusTraversalKeys_NoIDCheck(int id) {
         // Okay to return Set directly because it is an unmodifiable view
+        @SuppressWarnings("unchecked")
         Set<AWTKeyStroke> keystrokes = (focusTraversalKeys != null)
             ? focusTraversalKeys[id]
             : null;
--- a/jdk/src/share/classes/java/awt/Container.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/Container.java	Wed Jan 16 17:26:41 2013 +0400
@@ -161,7 +161,7 @@
     private boolean focusTraversalPolicyProvider;
 
     // keeps track of the threads that are printing this component
-    private transient Set printingThreads;
+    private transient Set<Thread> printingThreads;
     // True if there is at least one thread that's printing this component
     private transient boolean printing = false;
 
@@ -275,7 +275,7 @@
      */
     public Container() {
     }
-
+    @SuppressWarnings({"unchecked","rawtypes"})
     void initializeFocusTraversalKeys() {
         focusTraversalKeys = new Set[4];
     }
@@ -2006,7 +2006,7 @@
             try {
                 synchronized (getObjectLock()) {
                     if (printingThreads == null) {
-                        printingThreads = new HashSet();
+                        printingThreads = new HashSet<>();
                     }
                     printingThreads.add(t);
                     printing = true;
@@ -2148,7 +2148,7 @@
      * @since 1.4
      */
     public synchronized ContainerListener[] getContainerListeners() {
-        return (ContainerListener[]) (getListeners(ContainerListener.class));
+        return getListeners(ContainerListener.class);
     }
 
     /**
@@ -2599,9 +2599,9 @@
         if (GraphicsEnvironment.isHeadless()) {
             throw new HeadlessException();
         }
-        PointerInfo pi = (PointerInfo)java.security.AccessController.doPrivileged(
-            new java.security.PrivilegedAction() {
-                public Object run() {
+        PointerInfo pi = java.security.AccessController.doPrivileged(
+            new java.security.PrivilegedAction<PointerInfo>() {
+                public PointerInfo run() {
                     return MouseInfo.getPointerInfo();
                 }
             }
@@ -2682,7 +2682,7 @@
                                                                  y - comp.y,
                                                                  ignoreEnabled);
                 } else {
-                    comp = comp.locate(x - comp.x, y - comp.y);
+                    comp = comp.getComponentAt(x - comp.x, y - comp.y);
                 }
                 if (comp != null && comp.visible &&
                     (ignoreEnabled || comp.enabled))
@@ -2700,7 +2700,7 @@
                                                                  y - comp.y,
                                                                  ignoreEnabled);
                 } else {
-                    comp = comp.locate(x - comp.x, y - comp.y);
+                    comp = comp.getComponentAt(x - comp.x, y - comp.y);
                 }
                 if (comp != null && comp.visible &&
                     (ignoreEnabled || comp.enabled))
@@ -4637,7 +4637,7 @@
     private void startListeningForOtherDrags() {
         //System.out.println("Adding AWTEventListener");
         java.security.AccessController.doPrivileged(
-            new java.security.PrivilegedAction() {
+            new java.security.PrivilegedAction<Object>() {
                 public Object run() {
                     nativeContainer.getToolkit().addAWTEventListener(
                         LightweightDispatcher.this,
@@ -4652,7 +4652,7 @@
     private void stopListeningForOtherDrags() {
         //System.out.println("Removing AWTEventListener");
         java.security.AccessController.doPrivileged(
-            new java.security.PrivilegedAction() {
+            new java.security.PrivilegedAction<Object>() {
                 public Object run() {
                     nativeContainer.getToolkit().removeAWTEventListener(LightweightDispatcher.this);
                     return null;
--- a/jdk/src/share/classes/java/awt/Dialog.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/Dialog.java	Wed Jan 16 17:26:41 2013 +0400
@@ -1047,9 +1047,9 @@
                     // if this dialog is toolkit-modal, the filter should be added
                     // to all EDTs (for all AppContexts)
                     if (modalityType == ModalityType.TOOLKIT_MODAL) {
-                        Iterator it = AppContext.getAppContexts().iterator();
+                        Iterator<AppContext> it = AppContext.getAppContexts().iterator();
                         while (it.hasNext()) {
-                            AppContext appContext = (AppContext)it.next();
+                            AppContext appContext = it.next();
                             if (appContext == showAppContext) {
                                 continue;
                             }
@@ -1084,9 +1084,9 @@
                     // if this dialog is toolkit-modal, its filter must be removed
                     // from all EDTs (for all AppContexts)
                     if (modalityType == ModalityType.TOOLKIT_MODAL) {
-                        Iterator it = AppContext.getAppContexts().iterator();
+                        Iterator<AppContext> it = AppContext.getAppContexts().iterator();
                         while (it.hasNext()) {
-                            AppContext appContext = (AppContext)it.next();
+                            AppContext appContext = it.next();
                             if (appContext == showAppContext) {
                                 continue;
                             }
@@ -1396,7 +1396,7 @@
             if (d.shouldBlock(this)) {
                 Window w = d;
                 while ((w != null) && (w != this)) {
-                    w = (Window)(w.getOwner_NoClientCode());
+                    w = w.getOwner_NoClientCode();
                 }
                 if ((w == this) || !shouldBlock(d) || (modalityType.compareTo(d.getModalityType()) < 0)) {
                     blockers.add(d);
@@ -1611,7 +1611,7 @@
             setModal(modal);
         }
 
-        blockedWindows = new IdentityArrayList();
+        blockedWindows = new IdentityArrayList<>();
     }
 
     /*
--- a/jdk/src/share/classes/java/awt/Frame.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/Frame.java	Wed Jan 16 17:26:41 2013 +0400
@@ -353,7 +353,7 @@
      * @serial
      * @see java.awt.Window#ownedWindowList
      */
-    Vector ownedWindows;
+    Vector<Window> ownedWindows;
 
     private static final String base = "frame";
     private static int nameCounter = 0;
@@ -1242,7 +1242,7 @@
       //
       if (ownedWindows != null) {
           for (int i = 0; i < ownedWindows.size(); i++) {
-              connectOwnedWindow((Window) ownedWindows.elementAt(i));
+              connectOwnedWindow(ownedWindows.elementAt(i));
           }
           ownedWindows = null;
       }
--- a/jdk/src/share/classes/java/awt/KeyboardFocusManager.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/KeyboardFocusManager.java	Wed Jan 16 17:26:41 2013 +0400
@@ -416,7 +416,7 @@
         }
     }
 
-    static Set initFocusTraversalKeysSet(String value, Set targetSet) {
+    static Set<AWTKeyStroke> initFocusTraversalKeysSet(String value, Set<AWTKeyStroke> targetSet) {
         StringTokenizer tokens = new StringTokenizer(value, ",");
         while (tokens.hasMoreTokens()) {
             targetSet.add(AWTKeyStroke.getAWTKeyStroke(tokens.nextToken()));
--- a/jdk/src/share/classes/java/awt/Scrollbar.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/Scrollbar.java	Wed Jan 16 17:26:41 2013 +0400
@@ -1012,7 +1012,7 @@
      * @since 1.4
      */
     public synchronized AdjustmentListener[] getAdjustmentListeners() {
-        return (AdjustmentListener[])(getListeners(AdjustmentListener.class));
+        return getListeners(AdjustmentListener.class);
     }
 
     /**
--- a/jdk/src/share/classes/java/awt/TextArea.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/TextArea.java	Wed Jan 16 17:26:41 2013 +0400
@@ -123,7 +123,7 @@
      * Cache the Sets of forward and backward traversal keys so we need not
      * look them up each time.
      */
-    private static Set forwardTraversalKeys, backwardTraversalKeys;
+    private static Set<AWTKeyStroke> forwardTraversalKeys, backwardTraversalKeys;
 
     /*
      * JDK 1.1 serialVersionUID
@@ -143,10 +143,10 @@
         }
         forwardTraversalKeys = KeyboardFocusManager.initFocusTraversalKeysSet(
             "ctrl TAB",
-            new HashSet());
+            new HashSet<AWTKeyStroke>());
         backwardTraversalKeys = KeyboardFocusManager.initFocusTraversalKeysSet(
             "ctrl shift TAB",
-            new HashSet());
+            new HashSet<AWTKeyStroke>());
     }
 
     /**
--- a/jdk/src/share/classes/java/awt/TextComponent.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/TextComponent.java	Wed Jan 16 17:26:41 2013 +0400
@@ -606,7 +606,7 @@
      * @since 1.4
      */
     public synchronized TextListener[] getTextListeners() {
-        return (TextListener[])(getListeners(TextListener.class));
+        return getListeners(TextListener.class);
     }
 
     /**
--- a/jdk/src/share/classes/java/awt/TextField.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/TextField.java	Wed Jan 16 17:26:41 2013 +0400
@@ -507,7 +507,7 @@
      * @since 1.4
      */
     public synchronized ActionListener[] getActionListeners() {
-        return (ActionListener[])(getListeners(ActionListener.class));
+        return getListeners(ActionListener.class);
     }
 
     /**
--- a/jdk/src/share/classes/java/awt/Toolkit.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/Toolkit.java	Wed Jan 16 17:26:41 2013 +0400
@@ -863,7 +863,7 @@
                         new java.security.PrivilegedAction<Void>() {
                     public Void run() {
                         String nm = null;
-                        Class cls = null;
+                        Class<?> cls = null;
                         try {
                             nm = System.getProperty("awt.toolkit");
                             try {
--- a/jdk/src/share/classes/java/awt/Window.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/java/awt/Window.java	Wed Jan 16 17:26:41 2013 +0400
@@ -441,7 +441,7 @@
     transient Object anchor = new Object();
     static class WindowDisposerRecord implements sun.java2d.DisposerRecord {
         final WeakReference<Window> owner;
-        final WeakReference weakThis;
+        final WeakReference<Window> weakThis;
         final WeakReference<AppContext> context;
         WindowDisposerRecord(AppContext context, Window victim) {
             owner = new WeakReference<Window>(victim.getOwner());
@@ -1542,6 +1542,7 @@
     private static Window[] getWindows(AppContext appContext) {
         synchronized (Window.class) {
             Window realCopy[];
+            @SuppressWarnings("unchecked")
             Vector<WeakReference<Window>> windowList =
                 (Vector<WeakReference<Window>>)appContext.get(Window.class);
             if (windowList != null) {
@@ -1866,7 +1867,7 @@
      * @since 1.4
      */
     public synchronized WindowListener[] getWindowListeners() {
-        return (WindowListener[])(getListeners(WindowListener.class));
+        return getListeners(WindowListener.class);
     }
 
     /**
@@ -1882,7 +1883,7 @@
      * @since 1.4
      */
     public synchronized WindowFocusListener[] getWindowFocusListeners() {
-        return (WindowFocusListener[])(getListeners(WindowFocusListener.class));
+        return getListeners(WindowFocusListener.class);
     }
 
     /**
@@ -1898,7 +1899,7 @@
      * @since 1.4
      */
     public synchronized WindowStateListener[] getWindowStateListeners() {
-        return (WindowStateListener[])(getListeners(WindowStateListener.class));
+        return getListeners(WindowStateListener.class);
     }
 
 
@@ -2014,7 +2015,6 @@
                     break;
                 case WindowEvent.WINDOW_STATE_CHANGED:
                     processWindowStateEvent((WindowEvent)e);
-                default:
                     break;
             }
             return;
@@ -2382,12 +2382,14 @@
      *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
      * @since 1.4
      */
+    @SuppressWarnings("unchecked")
     public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
         if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) {
             throw new IllegalArgumentException("invalid focus traversal key identifier");
         }
 
         // Okay to return Set directly because it is an unmodifiable view
+        @SuppressWarnings("rawtypes")
         Set keystrokes = (focusTraversalKeys != null)
             ? focusTraversalKeys[id]
             : null;
@@ -2765,7 +2767,7 @@
    /*
     * Support for tracking all windows owned by this window
     */
-    void addOwnedWindow(WeakReference weakWindow) {
+    void addOwnedWindow(WeakReference<Window> weakWindow) {
         if (weakWindow != null) {
             synchronized(ownedWindowList) {
                 // this if statement should really be an assert, but we don't
@@ -2777,7 +2779,7 @@
         }
     }
 
-    void removeOwnedWindow(WeakReference weakWindow) {
+    void removeOwnedWindow(WeakReference<Window> weakWindow) {
         if (weakWindow != null) {
             // synchronized block not required since removeElement is
             // already synchronized
@@ -2792,6 +2794,7 @@
 
     private void addToWindowList() {
         synchronized (Window.class) {
+            @SuppressWarnings("unchecked")
             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)appContext.get(Window.class);
             if (windowList == null) {
                 windowList = new Vector<WeakReference<Window>>();
@@ -2801,8 +2804,9 @@
         }
     }
 
-    private static void removeFromWindowList(AppContext context, WeakReference weakThis) {
+    private static void removeFromWindowList(AppContext context, WeakReference<Window> weakThis) {
         synchronized (Window.class) {
+            @SuppressWarnings("unchecked")
             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)context.get(Window.class);
             if (windowList != null) {
                 windowList.remove(weakThis);
@@ -2945,7 +2949,7 @@
         // Deserialized Windows are not yet visible.
         visible = false;
 
-        weakThis = new WeakReference(this);
+        weakThis = new WeakReference<>(this);
 
         anchor = new Object();
         sun.java2d.Disposer.addRecord(anchor, new WindowDisposerRecord(appContext, this));
@@ -2956,7 +2960,7 @@
 
     private void deserializeResources(ObjectInputStream s)
         throws ClassNotFoundException, IOException, HeadlessException {
-            ownedWindowList = new Vector();
+            ownedWindowList = new Vector<>();
 
             if (windowSerializedDataVersion < 2) {
                 // Translate old-style focus tracking to new model. For 1.4 and
--- a/jdk/src/share/classes/sun/awt/image/SurfaceManager.java	Tue Jan 15 21:57:47 2013 +0400
+++ b/jdk/src/share/classes/sun/awt/image/SurfaceManager.java	Wed Jan 16 17:26:41 2013 +0400
@@ -88,7 +88,7 @@
         imgaccessor.setSurfaceManager(img, mgr);
     }
 
-    private ConcurrentHashMap cacheMap;
+    private ConcurrentHashMap<Object,Object> cacheMap;
 
     /**
      * Return an arbitrary cached object for an arbitrary cache key.
@@ -123,7 +123,7 @@
         if (cacheMap == null) {
             synchronized (this) {
                 if (cacheMap == null) {
-                    cacheMap = new ConcurrentHashMap(2);
+                    cacheMap = new ConcurrentHashMap<>(2);
                 }
             }
         }
@@ -245,7 +245,7 @@
 
     synchronized void flush(boolean deaccelerate) {
         if (cacheMap != null) {
-            Iterator i = cacheMap.values().iterator();
+            Iterator<Object> i = cacheMap.values().iterator();
             while (i.hasNext()) {
                 Object o = i.next();
                 if (o instanceof FlushableCacheData) {