PDA

View Full Version : [FIXED] [1.2.3] Dispatcher forwardEvent throws NPE



Adam Ward
2 Mar 2009, 3:36 PM
This is a very simple bug that can be seen by simply looking at the following static methods in the Dispatcher class:

/**
* Forwards an app event to the dispatcher.
*
* @param event the app event
*/
public static void forwardEvent(AppEvent event) {
instance.dispatch(event);
}

/**
* Creates and forwards an app event to the dispatcher.
*
* @param eventType the app event type
*/
public static void forwardEvent(int eventType) {
instance.dispatch(eventType);
}

/**
* Creates and fowards an app event to the dispatcher.
*
* @param eventType the app event type
* @param data the event data
*/
public static void forwardEvent(int eventType, Object data) {
instance.dispatch(new AppEvent(eventType, data));
}

/**
* Creates and fowards an app event to the dispatcher.
*
* @param eventType the app event type
* @param data the event data
* @param historyEvent true to mark event as a history event
*/
public static void forwardEvent(int eventType, Object data, boolean historyEvent) {
AppEvent ae = new AppEvent(eventType, data);
ae.historyEvent = historyEvent;
instance.dispatch(ae);
}

Not one of these methods checks to see if the instance variable is null. forwardEvent is a very handy shorthand method for getting the instance and dispatching an event, but you must call Dispatcher.get() before hand to initialize the singleton instance, which doesn't make sense to me.

To reproduce this bug, simply insert the following line at the very top of the onModuleLoad method in any application:

Dispatcher.forwardEvent(1);

Note: the value 1, can be substituted with any AppEvent or integer that maps to a specific AppEvent in your application.

sven
1 Apr 2009, 4:18 AM
Fixed in SVN.