Overriding JSNI methods causes crash ?

191 views
Skip to first unread message

Pierre

unread,
Mar 9, 2011, 12:02:53 PM3/9/11
to Google Web Toolkit
Hi all,

I am experiencing problems when using GWT / JSNI :

For tests, let's have a parent class with a JSNI method such as
public class TestParent {
public native void show()/*-{
$doc.write("PARENT JSNI");
}-*/;
}

and a child class overriding the parent JSNI method, such as
public class TestChild extends TestParent {
@Override
public void show() {
super.show();
RootPanel.get().add(new HTML("TestChild.show"));
}
}

and a basic EntryPoint :
public class Helloworld implements EntryPoint {

public void onModuleLoad() {
TestChild t = new TestChild();
t.show();
}
}

When calling the TestChild .show() method, we could assume getting the
result :
"PARENT JSNI" + "TestChild.show"

And in fact, we get the following result :
On Google Chrome 11 in development mode with GWT plugin :
"PARENT JSNI" and an error in the GWT plugin Development mode tab :

[DEBUG] [helloworld] - Rebinding
com.google.gwt.user.client.impl.WindowImpl
[DEBUG] [helloworld] - Checking rule <replace-with
class='com.google.gwt.user.client.impl.WindowImplIE'/>
[ERROR] [helloworld] - Error while executing the JavaScript provider
for property 'user.agent'
[ERROR] [helloworld] - Unable to get value of property 'user.agent'
[ERROR] [helloworld] - Deferred binding failed for
'com.google.gwt.user.client.impl.WindowImpl'; expect subsequent
failures
[ERROR] [helloworld] - Unable to load module entry point class
fr.helloworld.client.Helloworld (see associated exception for details)
[ERROR] [helloworld] - Failed to load module 'helloworld' from user
agent 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.24 (KHTML, like
Gecko) Chrome/11.0.696.0 Safari/534.24' at localhost:2222

This error stops any further instruction in the application.

On Firefox 3.6 in development mode with GWT plugin:
"PARENT JSNI" + "TestChild.show" (fine) but the browser is redirected
to http://127.0.0.1:8888/helloworld/hosted.html?helloworld and keeps
loading forever

When building the GWT project, the result are also different :
Chrome :
correct , works fine

Firefox 3.6 :
correct text displayed but the browser is redirected to helloworld/
F0E90C8F76FAE58BAB597BFF7095D19A.cache.html (compiled version for
firefox user agent) and keeps loading forever. I encountered the
problem on a real application, and of course the compiled application
was unable to run correctly.

Should I conclude that developer should never try to override JSNI
methods ?
Should we guess that it is a GWT compiler bug ?

Andi

unread,
Mar 10, 2011, 4:52:20 AM3/10/11
to google-we...@googlegroups.com
maybe you should try "console.log" or "window.alert" instead of document.write..

andi

(vom fon)

> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
>

Pierre

unread,
Mar 10, 2011, 5:34:05 AM3/10/11
to Google Web Toolkit
Thanks for you answer,

In fact, solutions that don't write in the page (such as alert or
console) do work but it doesn't explain why the problems happens when
I use document.write

On 10 mar, 10:52, Andi <andi.ba...@googlemail.com> wrote:
> maybe you should try "console.log" or "window.alert" instead of document.write..
>
> andi
>
> (vom fon)
>
> > tohttp://127.0.0.1:8888/helloworld/hosted.html?helloworldand keeps

Thomas Broyer

unread,
Mar 10, 2011, 5:51:22 AM3/10/11
to google-we...@googlegroups.com
document.write(), unless executed synchronously as the document loads, implies document.open() which replaces the current document with a new, blank one (similar to navigating to about:blank).
Reply all
Reply to author
Forward
0 new messages