I'm being stuck for hours on this simple implementation of the GWT SimpleEventbus.
Is there anything wrong with this setup? What could be a possible reason for this?
I'm using the web.binderyEventbus
import com.google.web.bindery.event.shared.SimpleEventBus;
The Eventbus is initalized in my Entrypoint Class.
public void onModuleLoad() {
ApplicationEvents = new SimpleEventBus();
It's then injected into the Singleton LoadData and into the MainView (UIBinder class no MVP).
LoadData.initLoadData(ApplicationEvents);
view = new MainView(ApplicationEvents);
initLoadData is basically an alias for the constructor, except that it's not returning anything.
public class LoadData {
private final SimpleEventBus eventBus;
private LoadData(final SimpleEventBus bus) {
eventBus = bus;
...
}
public static void initLoadData(final SimpleEventBus bus){
if (instance == null){
instance = new LoadData(bus);
}
}
The Eventbus is injected to the MainView like this.
public class MainView extends Composite {
private final SimpleEventBus eventbus;
public MainView(final SimpleEventBus bus) {
eventbus = bus;
...
Then the handler is registered.
eventbus.addHandler(EntriesReceiveEvent.TYPE, new EntriesReceiveEventHandler() {
@Override
public void onEntriesReceive(EntriesReceiveEvent event) {
...
}
});
And at the end of the method I have it call a method in LoadData.
LoadData.getLoadData().fetchYears(); //alias for loadIndex
The loadIndex method in LoadData.java
private void loadIndex() {
System.out.println(eventBus.toString());
if(indexEntries == null){
AsyncCallback..
public void onSuccess(Map<Short, IndexEntry> result) {
eventBus.fireEvent(new EntriesReceiveEvent());
//^^ LoadData.java:190
EntriesReceiveEvent.java
import com.google.gwt.event.shared.GwtEvent;
public class EntriesReceiveEvent extends GwtEvent<EntriesReceiveEventHandler> {
public static Type<EntriesReceiveEventHandler> TYPE =
new Type<EntriesReceiveEventHandler>();
@Override
public Type<EntriesReceiveEventHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(EntriesReceiveEventHandler handler) {
handler.onEntriesReceive(this);
}
}
And it's handler EntriesReceiveEventHandler.java
import com.google.gwt.event.shared.EventHandler;
public interface EntriesReceiveEventHandler extends EventHandler {
void onEntriesReceive(EntriesReceiveEvent event);
}
Finally the Exception.
11:36:57.417 [ERROR] [] Uncaught exception escaped
com.google.web.bindery.event.shared.UmbrellaException: Exception caught: null
at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:203)
at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
at com.SoftwareEngineering.client.LoadData$2.onSuccess(LoadData.java:190)
at com.SoftwareEngineering.client.LoadData$2.onSuccess(LoadData.java:1)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:232)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:258)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:412)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Unknown Source)
I thought that the Eventbus might not be the same as I didn't know if they're all talking to the same Eventbus. This site however proved my concerns to be wrong.
Side question: Do you consider the Singleton in this context bad? It's a rather small project and the LoadData which handles all RPC requests needs to be globally available.
Thank you for any help!
The NPE you have there is wrapped up in a Umbrella exception. This means that one of the event handlers actually threw the exception. The standard procedure in that case is to continue calling the rest of the handlers, then throw an umbrella exception containing all errors that happened while firing.
To read the real exception, continue your way up the stack - read the rest of the log past where this happened, and see what happened in the handler (probably your own event handler code, or in some code that your handler calls).
Another way to dig into issues like this: Use your IDE's debugger and set a breakpoint on all thrown NullPointerExceptions. This will pause the debugger the instant that a NPE happens so you can see it right away instead of digging through the logs.