Sirish Kumar Bethala
Sirish Kumar Bethala

Reputation: 9269

AWT EventQqueue AccessControlException

I am pushing my own test event queue over the System eventqueue. And in TestEQueue I have over loaded the dispatchEvent method with one call to super.dispatchEvent

      TestEQueue mytestqueue = new TestEQueue();
      Toolkit.getDefaultToolkit().getSystemEventQueue().push(TestEQueue);

But for some reason dispatching in the new TestQueue fails with AccessControlException. Where as the same event is successfully dispatched in the main program without TestEQueue.

How can this be possible as both the queues will running in the same thread group? How can I debug this issue? This is part of a very large test codebase, so I am not able to copy the functional code. Can this be related to security manager?

Upvotes: 1

Views: 221

Answers (2)

trashgod
trashgod

Reputation: 205865

Note that push() replaces the existing EventQueue; it doesn't add a new queue. I think the premise of your question may be incorrect. See also this Q&A.

Upvotes: 1

mKorbel
mKorbel

Reputation: 109823

nobody know how do you built your own test event queue over the System eventqueue, maybe you miss there invokeAndWait,

useful infos and here

just my curiosity, if your test ends with success, then please test that with SwingUtilities.invokeAndWait, if there some differencies (awaiting nothing), and I marked your thread for notifying any changes :-)

this code should be works for Testing purposes,

import java.awt.AWTEvent;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.lang.reflect.InvocationTargetException;

public class QueueTest {

    public static void main(String[] args) throws InterruptedException, InvocationTargetException {
        EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        eventQueue.push(new MyEventQueue());

        EventQueue.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                System.out.println("Run");
            }
        });
    }

    private static class MyEventQueue extends EventQueue {

        @Override
        public void postEvent(AWTEvent theEvent) {
            System.out.println("Event Posted");
            super.postEvent(theEvent);
        }
    }

    private QueueTest() {
    }
}

Upvotes: 1

Related Questions