问题
There is a part of our application that does this...
int x = DOM.getElementById("x").getPropertyInt("value");
int y = DOM.getElementById("y").getPropertyInt("value");
int w = DOM.getElementById("w").getPropertyInt("value");
int h = DOM.getElementById("h").getPropertyInt("value");
Every call to DOM.getElemendById("something") returns null (which I expect as I removed them) but calling .getPropertyInt("value") on that return value of null is not causing a NullPointerException. In dev mode I am able to step through all of these statements and watch x,y,w,h all be assigned to zero. If I evaluate one of these statements in the Intellij evaluator in the debugger there is a NullPointerException thrown.
Doesn't this seem slightly insane to anybody else?
回答1:
The docs say:
Exceptions: try, catch, finally and user-defined exceptions are supported as
normal, although Throwable.getStackTrace() is not meaningfully supported in
production mode.
Note: Several fundamental exceptions implicitly produced by the Java VM, most
notably NullPointerException, StackOverflowError, and OutOfMemoryError, do not
occur in production mode as such. Instead, a JavaScriptException is produced for
any implicitly generated exceptions. This is because the nature of the underlying
JavaScript exception cannot be reliably mapped onto the appropriate Java
exception type.
回答2:
Wow it looks like anything created by GWT overlay types are able to do this...
http://code.google.com/p/google-web-toolkit/issues/detail?id=5030
来源:https://stackoverflow.com/questions/6051699/gwt-call-to-dom-getelementbyid-not-causing-a-nullpointerexception-when-it-should