After some debugging,I found “com.google.gwt.event.shared.UmbrellaException:One or
more exceptions caught, see full set in UmbrellaException#getCauses’ when calling method: [nsIDOMEventListener::handleEvent]”(in web model) is caused by runtime null pointer.Question is why this kind of runtime null pointer exception didn’t got thrown out under host model.Actually,blow code won’t thrown out any exception and even got alert popup in my laptop(gwt 2.4+java 7 64bit+ubuntu 12.04 64bit+eclipse 3.7).Anybody knows how to enforce eclipse throw out exception whenever a runtime null on JavascriptObject pointer occurs.
public class GWTTest implements EntryPoint
{
public static class JsObj extends JavaScriptObject
{
protected JsObj()
{
}
public final native void setValue(String Value)/*-{
this.Value=Value;
alert(Value);
}-*/;
}
public void onModuleLoad()
{
JsObj jsObj = null;
jsObj.setValue("val");
}
}
The compiler performs a number of optimizations to transform GWT/Java into Javascript.
That said… When I compile your sample, the body of onModuleLoad() is optimized out to this:
This is the GWT compiler’s way of saying ‘this will never work’ – it notices that the value is always null, and so the method can’t be invoked on it. But in Dev Mode, apparently the null object is left pointing at the
windowobject in JavaScript. This is filed at http://code.google.com/p/google-web-toolkit/issues/detail?id=6625 in the GWT project.If you need to make sure you don’t act on a null, test for null before calling the method – it’ll get optimized out if, in a test like yours, the value is always null. Runtime exceptions shouldn’t be used for controlling code anyway, so you should never rely on a NullPointerException to do anything in your code.