changeset 6359:898c92b7ab12

8011695: [tck-red] Application can not be run, the Security Warning dialog is gray. Summary: EventQueue shoudn't use AppContext.getAppContext() to obtain its AppContext. Reviewed-by: art, serb
author leonidr
date Tue, 16 Apr 2013 18:52:44 +0400
parents d59dc08047fd
children fe514475bc17
files src/share/classes/java/awt/EventQueue.java src/share/classes/javax/swing/RepaintManager.java src/share/classes/sun/awt/SunToolkit.java
diffstat 3 files changed, 27 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/awt/EventQueue.java	Mon Apr 15 14:15:21 2013 +0400
+++ b/src/share/classes/java/awt/EventQueue.java	Tue Apr 16 18:52:44 2013 +0400
@@ -174,6 +174,11 @@
      */
     private volatile int waitForID;
 
+    /*
+     * AppContext corresponding to the queue.
+     */
+    private final AppContext appContext;
+
     private final String name = "AWT-EventQueue-" + threadInitNumber.getAndIncrement();
 
     private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventQueue");
@@ -220,8 +225,9 @@
          * completes thus causing mess in thread group to appcontext mapping.
          */
 
-        pushPopLock = (Lock)AppContext.getAppContext().get(AppContext.EVENT_QUEUE_LOCK_KEY);
-        pushPopCond = (Condition)AppContext.getAppContext().get(AppContext.EVENT_QUEUE_COND_KEY);
+        appContext = AppContext.getAppContext();
+        pushPopLock = (Lock)appContext.get(AppContext.EVENT_QUEUE_LOCK_KEY);
+        pushPopCond = (Condition)appContext.get(AppContext.EVENT_QUEUE_COND_KEY);
     }
 
     /**
@@ -235,7 +241,7 @@
      * @throws NullPointerException if <code>theEvent</code> is <code>null</code>
      */
     public void postEvent(AWTEvent theEvent) {
-        SunToolkit.flushPendingEvents();
+        SunToolkit.flushPendingEvents(appContext);
         postEventPrivate(theEvent);
     }
 
@@ -526,7 +532,7 @@
              * of the synchronized block to avoid deadlock when
              * event queues are nested with push()/pop().
              */
-            SunToolkit.flushPendingEvents();
+            SunToolkit.flushPendingEvents(appContext);
             pushPopLock.lock();
             try {
                 AWTEvent event = getNextEventPrivate();
@@ -566,7 +572,7 @@
              * of the synchronized block to avoid deadlock when
              * event queues are nested with push()/pop().
              */
-            SunToolkit.flushPendingEvents();
+            SunToolkit.flushPendingEvents(appContext);
             pushPopLock.lock();
             try {
                 for (int i = 0; i < NUM_PRIORITIES; i++) {
@@ -874,7 +880,6 @@
             newEventQueue.previousQueue = topQueue;
             topQueue.nextQueue = newEventQueue;
 
-            AppContext appContext = AppContext.getAppContext();
             if (appContext.get(AppContext.EVENT_QUEUE_KEY) == topQueue) {
                 appContext.put(AppContext.EVENT_QUEUE_KEY, newEventQueue);
             }
@@ -935,7 +940,6 @@
                 topQueue.dispatchThread.setEventQueue(prevQueue);
             }
 
-            AppContext appContext = AppContext.getAppContext();
             if (appContext.get(AppContext.EVENT_QUEUE_KEY) == this) {
                 appContext.put(AppContext.EVENT_QUEUE_KEY, prevQueue);
             }
@@ -1028,7 +1032,6 @@
     final void initDispatchThread() {
         pushPopLock.lock();
         try {
-            AppContext appContext = AppContext.getAppContext();
             if (dispatchThread == null && !threadGroup.isDestroyed() && !appContext.isDisposed()) {
                 dispatchThread = AccessController.doPrivileged(
                     new PrivilegedAction<EventDispatchThread>() {
@@ -1114,7 +1117,7 @@
      * <code>removeNotify</code> method.
      */
     final void removeSourceEvents(Object source, boolean removeAllEvents) {
-        SunToolkit.flushPendingEvents();
+        SunToolkit.flushPendingEvents(appContext);
         pushPopLock.lock();
         try {
             for (int i = 0; i < NUM_PRIORITIES; i++) {
--- a/src/share/classes/javax/swing/RepaintManager.java	Mon Apr 15 14:15:21 2013 +0400
+++ b/src/share/classes/javax/swing/RepaintManager.java	Tue Apr 16 18:52:44 2013 +0400
@@ -342,7 +342,7 @@
 
         // Queue a Runnable to invoke paintDirtyRegions and
         // validateInvalidComponents.
-        scheduleProcessingRunnable();
+        scheduleProcessingRunnable(SunToolkit.targetToAppContext(invalidComponent));
     }
 
 
@@ -431,7 +431,7 @@
 
         // Queue a Runnable to invoke paintDirtyRegions and
         // validateInvalidComponents.
-        scheduleProcessingRunnable();
+        scheduleProcessingRunnable(SunToolkit.targetToAppContext(c));
     }
 
     /**
@@ -1373,10 +1373,6 @@
         return paintManager;
     }
 
-    private void scheduleProcessingRunnable() {
-        scheduleProcessingRunnable(AppContext.getAppContext());
-    }
-
     private void scheduleProcessingRunnable(AppContext context) {
         if (processingRunnable.markPending()) {
             Toolkit tk = Toolkit.getDefaultToolkit();
--- a/src/share/classes/sun/awt/SunToolkit.java	Mon Apr 15 14:15:21 2013 +0400
+++ b/src/share/classes/sun/awt/SunToolkit.java	Tue Apr 16 18:52:44 2013 +0400
@@ -97,6 +97,14 @@
      */
     public final static int MAX_BUTTONS_SUPPORTED = 20;
 
+    /**
+     * Creates and initializes EventQueue instance for the specified
+     * AppContext.
+     * Note that event queue must be created from createNewAppContext()
+     * only in order to ensure that EventQueue constructor obtains
+     * the correct AppContext.
+     * @param appContext AppContext to associate with the event queue
+     */
     private static void initEQ(AppContext appContext) {
         EventQueue eventQueue;
 
@@ -514,13 +522,17 @@
      * EventQueue yet.
      */
     public static void flushPendingEvents()  {
+        AppContext appContext = AppContext.getAppContext();
+        flushPendingEvents(appContext);
+    }
+
+    public static void flushPendingEvents(AppContext appContext)  {
         flushLock.lock();
         try {
             // Don't call flushPendingEvents() recursively
             if (!isFlushingPendingEvents) {
                 isFlushingPendingEvents = true;
                 try {
-                    AppContext appContext = AppContext.getAppContext();
                     PostEventQueue postEventQueue =
                         (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
                     if (postEventQueue != null) {