@@ -113,32 +113,30 @@ public <E extends SciJavaEvent> void publishLater(final E e) {
113113
114114 @ Override
115115 public List <EventSubscriber <?>> subscribe (final Object o ) {
116- List <EventSubscriber <?>> subscribers = Collections .emptyList ();
117116 final List <Method > eventHandlers =
118117 ClassUtils .getAnnotatedMethods (o .getClass (), EventHandler .class );
118+ if (eventHandlers .isEmpty ()) return Collections .emptyList ();
119+
120+ final ArrayList <EventSubscriber <?>> subscribers = new ArrayList <>();
121+ for (final Method m : eventHandlers ) {
122+ // verify that the event handler method is valid
123+ final Class <? extends SciJavaEvent > eventClass = getEventClass (m );
124+ if (eventClass == null ) {
125+ log .warn ("Invalid EventHandler method: " + m );
126+ continue ;
127+ }
119128
120- if (!eventHandlers .isEmpty ()) {
121- subscribers = new ArrayList <>();
122- for (final Method m : eventHandlers ) {
123- // verify that the event handler method is valid
124- final Class <? extends SciJavaEvent > eventClass = getEventClass (m );
125- if (eventClass == null ) {
126- log .warn ("Invalid EventHandler method: " + m );
127- continue ;
128- }
129-
130- // verify that the event handler key isn't already claimed
131- final String key = m .getAnnotation (EventHandler .class ).key ();
132- if (!key .isEmpty ()) {
133- synchronized (keys ) {
134- if (keys .contains (key )) continue ;
135- keys .add (key );
136- }
129+ // verify that the event handler key isn't already claimed
130+ final String key = m .getAnnotation (EventHandler .class ).key ();
131+ if (!key .isEmpty ()) {
132+ synchronized (keys ) {
133+ if (keys .contains (key )) continue ;
134+ keys .add (key );
137135 }
138-
139- // subscribe the event handler
140- subscribers .add (subscribe (eventClass , o , m ));
141136 }
137+
138+ // subscribe the event handler
139+ subscribers .add (subscribe (eventClass , o , m ));
142140 }
143141 return subscribers ;
144142 }
0 commit comments