GWT call to DOM.getElementById not causing a NullPointerException when it should

断了今生、忘了曾经 提交于 2020-01-01 12:13:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!