So, the abstraction layer provided by GWT just leaked–well, more of a flood than a leak.
I am working on a site that is pulling in an html fragment which included some javascript code via an XML HttpRequest. This new code will make paging the results of a search quicker, hopefully leading to happier users. For reasons too obscure to go into, I was creating a variable named ‘r1’ which I was then adding to the DOM. The name was completely arbitrary, and was due to laziness (hey, why type 3 characters when you can type 2?).
Fast forward to today, when we’re getting ready to launch the update. Occasionally, but not often, code that GWT was executing was throwing an exception. One of the other developers found it because some functionality was disabled. Here’s what that exception looked like:
exception: (NS_ERROR_XPC_CANT_CONVERT_WN_TO_FUN): Cannot convert WrappedNative to function
QueryInterface: function QueryInterface() {
[native code]
}
result: 2153185293
filename: http://stageserver/gwt/2B17113CD349EDFD95DC846F38AB0857.cache.html
lineNumber: 4268
columnNumber: 0
inner: null
data: null
initialize: function initialize() {
[native code]
}
Now, usually, the first thing I do when I see an exception is to recompile the GWT with -style DETAILED
instead of -style OBF
and see where the error occurs. However, when I did that, I didn’t see the error message any more.
OK, I added more debugging. If I added a certain number of alert statements, the error message was nowhere to be found. OK, go back to the previous code. Try different pages, different browsers. Sometimes the exception reared its head, other times it didn’t. It appeared on some browsers and not others. Sprinkled alerts throughout the code, found the exact line where the exception was being thrown. All that line did was create a click listener.
Nothing really clear on google; however, this post was useful in pointing to the error message being a collision between a function name and a DOM element. Searching the GWT google group was not helpful. I tried using the Firebug debugger, but on obfuscated source, it was not helpful to me.
These kind of bugs make me want to tear out my hair. Hardly reproducible bugs are no fun. However, I finally found the issue (if I hadn’t, I’d still be working and wouldn’t be posting, that’s for sure).
How I finally solved it: I was getting a line number. I finally edited the generated GWT .cache.html file and added some newlines. This would let me find out exactly which function was really causing the issue.
And, lo and behold, the problematic function was named ‘r1’.
Changing the name of the DOM element fixed this issue. Beware short named javascript DOM elements when working with GWT.
Hope this helps you.