Question

I have my own emulation of java.util.Timer (and quite a lot of other stuff missing in GWT). I have even a JUnit test proving it works in the browser.

I've just tried to convert some third-party library to GWT, which needed a Timer, and in some part of it, I call:

SystemUtils.getTimer().scheduleAtFixedRate(timerTask, value, value);

But the GWT compiler turns getTimer().scheduleAtFixedRate() to:

getTimer().nullMethod()

SystemUtils.getTimer() is a static method. I have googled for nullMethod(), but most hits are about:

null.nullMethod();

That doesn't apply to me. What could be going wrong, and what can I do to fix it?

[EDIT] Actually, the java.util.Timer emulation itself works, but it seems that (atm?) SystemUtils.getTimer() returns "undefined". Could that be the reason? Since getTimer() returns an instance created dynamically, how could the GWT compiler possibly make any assumption about the return value of getTimer(), and the presence/usage of the methods of the Timer type?

Was it helpful?

Solution

When I have seen this kind of errors it was caused by unreachable code: GWT had determined that some code was not reachable, turning off compilation for some stuff, but then it still somehow tried to link the unreachable code, showing this kind of errors.

OTHER TIPS

For completeness sake

If this error shows up (which often happens after deploying to App Engine) then compile without obfuscation, turn off super dev mode, restart jetty and refresh the browser. Open the generated javascript and find where the problem occurs by searching for 'nullMethod'. You'll see that the compiler may have removed whole chunks of code that it believes is 'unreachable'.

The code surrounding 'null.nullMethod' is probably very different than what you expected. The simplest way around this is to add a null /undefined check and initializing whatever variable that is generated as 'null'. This forces the compiler to reconsider because now the variable can never be null and the code that follows it must be reachable.

For example, if null.nullMethod is found and 'null' is actually supposed to be var a = ... then add if(a == null) { a = ""; } before it (in Java of course).

For anybody who struggles with this null.nullMethod issue:

It may be possible that your GWT compiler isn't able to find the properties of your JSON bean object if your object variable is declared with its interface type:

MyTypeIF item = ...;
...
item.getStart();
...

In my scenario, GWT compiled that into:

MyTypeIF item = ...;
...
null.nullMethod();
...

Instead, I had to declare and cast it to its real implementation class:

JSMyType item = (JSMyType)...;
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top