diff options
author | Thomas Watson | 2007-05-15 21:31:48 +0000 |
---|---|---|
committer | Thomas Watson | 2007-05-15 21:31:48 +0000 |
commit | 10720db0bbfbb73f0194efc2d8bbb0d2ceb9be18 (patch) | |
tree | 46ac0da6107dafde6d33de092a3a7628080fe597 | |
parent | 064243e49b8b3a07a9cec118e2f2290794fc2f6a (diff) | |
download | rt.equinox.bundles-bug183883.tar.gz rt.equinox.bundles-bug183883.tar.xz rt.equinox.bundles-bug183883.zip |
- must throw SecurityException if TopicPermission PUBLISH is not grantedbug183883
- must throw NPE if event == null
-rw-r--r-- | bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/event/EventAdminImpl.java | 35 | ||||
-rw-r--r-- | bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/event/EventHandlerWrapper.java | 4 |
2 files changed, 19 insertions, 20 deletions
diff --git a/bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/event/EventAdminImpl.java b/bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/event/EventAdminImpl.java index 6b6d32e95..de553a880 100644 --- a/bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/event/EventAdminImpl.java +++ b/bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/event/EventAdminImpl.java @@ -86,20 +86,26 @@ public class EventAdminImpl implements EventAdmin { * for asyncronous delivery. */ private void dispatchEvent(Event event, boolean isAsync) { - if (eventManager == null) { + // keep a local copy in case we are stopped in the middle of dispatching + EventManager currentManager = eventManager; + if (currentManager == null) { // EventAdmin is stopped return; } if (event == null) { log.log(LogService.LOG_ERROR, EventAdminMsg.EVENT_NULL_EVENT); - return; + // continue from here will result in an NPE below; the spec for EventAdmin does not allow for null here } String topic = event.getTopic(); - if (!checkTopicPermissionPublish(topic)) { - log.log(LogService.LOG_ERROR, NLS.bind(EventAdminMsg.EVENT_NO_TOPICPERMISSION_PUBLISH, event.getTopic())); - return; + try { + checkTopicPermissionPublish(topic); + } catch (SecurityException e) { + String msg = NLS.bind(EventAdminMsg.EVENT_NO_TOPICPERMISSION_PUBLISH, event.getTopic()); + log.log(LogService.LOG_ERROR, msg); + // must throw a security exception here according to the EventAdmin spec + throw e; } Set eventHandlers = handlers.getHandlers(topic); @@ -119,7 +125,7 @@ public class EventAdminImpl implements EventAdmin { } // Create the listener queue for this event delivery - ListenerQueue listenerQueue = new ListenerQueue(eventManager); + ListenerQueue listenerQueue = new ListenerQueue(currentManager); // Add the listeners to the queue and associate them with the event // dispatcher listenerQueue.queueListeners(listeners, handlers); @@ -136,20 +142,13 @@ public class EventAdminImpl implements EventAdmin { * Checks if the caller bundle has right PUBLISH TopicPermision. * * @param topic - * @return true if it has the right permission, false otherwise. + * @throws SecurityException if the caller does not have the right to PUBLISH TopicPermission */ - private boolean checkTopicPermissionPublish(String topic) { + private void checkTopicPermissionPublish(String topic) throws SecurityException{ SecurityManager sm = System.getSecurityManager(); - if (sm == null) { - return true; - } - try { - sm.checkPermission(new TopicPermission(topic, TopicPermission.PUBLISH)); - } - catch (SecurityException e) { // fall through and return false - return false; - } - return true; + if (sm == null) + return; + sm.checkPermission(new TopicPermission(topic, TopicPermission.PUBLISH)); } } diff --git a/bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/event/EventHandlerWrapper.java b/bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/event/EventHandlerWrapper.java index c3b3b0b0e..190c4945f 100644 --- a/bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/event/EventHandlerWrapper.java +++ b/bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/event/EventHandlerWrapper.java @@ -46,7 +46,7 @@ public class EventHandlerWrapper { /** * Cache values from service properties * - * @return true of the handler should be called; false if the handler should not be called + * @return true if the handler should be called; false if the handler should not be called */ public synchronized boolean init() { topics = null; @@ -144,7 +144,7 @@ public class EventHandlerWrapper { } /** - * Dispatch event to handler. Perform final tests before actually calling the hanlder. + * Dispatch event to handler. Perform final tests before actually calling the handler. * * @param event The event to dispatch * @param perm The permission to be checked |