ClassCastException in generics

209 views
Skip to first unread message

Kirill Prazdnikov

unread,
Aug 18, 2017, 10:01:47 AM8/18/17
to GWT Users
Hi, I`m always getting ClassCastException if I use @JsType(isNative = true) object as a generic template argument.

Is it possbile to do something with that ?
Is it possbile to avoid check-cast generation if the generic is used with @JsType type ?

Thanks

Vassilis Virvilis

unread,
Aug 18, 2017, 10:05:47 AM8/18/17
to google-we...@googlegroups.com
Try to annotate it with

    @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")

Hope that helps




--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsub...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.



--
Vassilis Virvilis

Kirill Prazdnikov

unread,
Aug 18, 2017, 10:07:35 AM8/18/17
to GWT Users
I do not think I can use name = "Object" with

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public abstract class ArrayBuffer { ... }

Vassilis Virvilis

unread,
Aug 18, 2017, 10:10:50 AM8/18/17
to google-we...@googlegroups.com
if it's an array (like a javascript array) use name = "Array".

If it is an Object that encapsulates array functionality use "Object".



On Fri, Aug 18, 2017 at 5:05 PM, Vassilis Virvilis <vas...@gmail.com> wrote:
Try to annotate it with

    @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")

Hope that helps


On Fri, Aug 18, 2017 at 5:01 PM, Kirill Prazdnikov <pki...@gmail.com> wrote:
Hi, I`m always getting ClassCastException if I use @JsType(isNative = true) object as a generic template argument.

Is it possbile to do something with that ?
Is it possbile to avoid check-cast generation if the generic is used with @JsType type ?

Thanks

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.

To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.



--
Vassilis Virvilis



--
Vassilis Virvilis

Kirill Prazdnikov

unread,
Aug 18, 2017, 10:47:17 AM8/18/17
to google-we...@googlegroups.com
I do not get your suggestion. 
How that will help.

Vassilis Virvilis

unread,
Aug 18, 2017, 11:05:16 AM8/18/17
to google-we...@googlegroups.com
Look, it may not help.

In case if it works I don't understand well enough to explain the specifics. Maybe it checks javascript castability. Which reminds me... if your Object can be instantiated from javascript use that info i.e.

@JsType(isNative = true, namespace = "jslib.namespace.whatever" name = "ArrayBuffer")

If your javascript object is not ArrayBuffer but array_buffer make sure package name and name matches.

This is what I remember. I may be wrong. I have been before.

     Vassilis

Tony BenBrahim

unread,
Aug 20, 2017, 10:22:38 AM8/20/17
to GWT Users

My, understanding, because I have noticed the same many times in the past few weeks.

@JsType may (and that is a very weak may) work for a native type as long as you do not use it as you do not use it as a generic type argument. As soon as you do, for example, adding it to List<SomeType>, , cast checking kicks in and you end up with a class cast exception if SomeType is only annotated with @JsType. There is another case when it kicks in also. I have noticed also a couple times that code with just @JsType worked fine in superdev mode when not used in a generic context, but failed with a class cast exception, once compiled for release. As Vassillis mentioned, I am now conditioned to always specify the type name and package when isNative=true. Object is most commonly the name, but it could be different. However, Object will always be correct. The casting code in GWT is in Cast.java and the failure typically happens in the jsintanceof method, called from castToNative, with one of the parameters being null because the type name specified in the @JsType annotation is incorrect or missing. In your case since ArrayBuffer is an instance of Object, either Object or ArrayBuffer should work for the type name.

You can disable cast checking, but only when compiling for production, and not in superdev mode, by using the -XdisableCastChecking flag. For most applications that get data from the network and display it on the page, this will have no noticeable effect whatsoever, so it is best avoided. There is also the @UnecheckedCast annotation, which can be applied to selected methods in the critical path of performance sensitive code, and again, only takes effect in code compile for release, not superdev mode.

You would not want to disable cast checking in superdev mode anyways. I just finished porting an AngularJS/TypeScript application to GWT, and found a number of silent bugs in the old typescript (bugs that doe generate any output in the dev console) thanks to GWT cast checking. Typescript gives the illusion of types, but there is no runtime type checking when you cast something, GWT really does check, and that is a major advantage you would not want to lose.

Thomas Broyer

unread,
Aug 20, 2017, 1:54:51 PM8/20/17
to GWT Users
Think about what this means.

@JsType(isNative=true) applied to a com.example.foo.client.Foo class is strictly equivalent to @JsType(isNative=true, namespace="com.example.foo.client", name="Foo"), which means, literally: "this Java class is an "interop mapping" to be able to work with the com.example.foo.client.Foo JS "class/type" from Java code". This implies that you expect instances of that class to be "instanceof com.example.foo.client.Foo" (in JS), and btw such an "instanceof" in Java will literally translate to that same "instanceof" in JS.

If you do not intend to create instances of that Java type, then you can use a Java interface and use namespace=GLOBAL,name="?" (see note in http://www.gwtproject.org/javadoc/latest/jsinterop/annotations/JsType.html)
If you want to use a Java class and/or need to create instances (but do not have to use a specific JS constructor), then you'll want to use namespace=GLOBAL,name="Object".

But as Tony said, you do not want to disable cast-checking. If you think you need to do it, then you're most likely doing it wrong.

Kirill Prazdnikov

unread,
Aug 21, 2017, 8:39:19 AM8/21/17
to GWT Users
Ok, according to the doc, the name:
 Customizes the name of the type in generated JavaScript. If not provided, the simple Java name will be used.

That means that for my case  

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public abstract class ArrayBuffer { ... }

This is equvavlent to (name = "ArrayBuffer"). Which was suggested above. Right ? 

I tried the following without any success:
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "ArrayBuffer")

JavaScriptObject jsType is stil null and checkcast failed.

But this works:

@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")

In that case GWT calls castToJsObject, which does not do type checking, instead of castToNative. castToNative does type checks.

However I still don`t think that name="Object" is correct for native ArrayBuffer. 
If I understand JsInterop correctly, when want to call a @JsConstructor form java I must assign a proper name, right ?

Vassilis Virvilis

unread,
Aug 21, 2017, 8:45:59 AM8/21/17
to google-we...@googlegroups.com
From the console of the web browser: What is it required to create a new ArrayBuffer?

For example is this enough?
> new $wnd.ArrayBuffer();

or something else is required - such as
> new $wnd.package1.package2.ArrayBuffer();

or maybe it is
> new $wnd.package1.package2.array_buffer();

The answers to these questions will show what you need to put in 'namespace' argument and what in 'name'.

Hope that helps





--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsub...@googlegroups.com.

To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.



--
Vassilis Virvilis

Kirill Prazdnikov

unread,
Aug 21, 2017, 9:52:26 AM8/21/17
to GWT Users

Vassilis Virvilis

unread,
Aug 21, 2017, 10:06:26 AM8/21/17
to google-we...@googlegroups.com
Oh I see. I forgot about that.

These ought to work.
@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public abstract class ArrayBuffer { ... }

 
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "ArrayBuffer")

I don't know what else may be the problem.

What else is it going on java side?
Maybe the instance you are trying to cast is null?
What else can it be if not ArrayBuffer (hence the need of generic)? An ArrayBuffer extension?
If you print the variable you are trying to cast in the console? Does it says that's an ArrayBuffer?

I jave been fighting with jsinterop exceptions for some time and I know that it can be very frustrating.

     Vassilis

 

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsub...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.



--
Vassilis Virvilis

Kirill Prazdnikov

unread,
Aug 21, 2017, 11:07:22 AM8/21/17
to GWT Users
This is perfectly fine ArrayBuffer which I got from the system call to FileReader.onLoad callback. 
It correct, it loads and I finally read a 3d ojbect form it.

What else can it be if not ArrayBuffer (hence the need of generic)? An ArrayBuffer extension?
 
I`m trying to generalize the drag-drop code across GWT and JVM clients. 
We have a portable UI code and it is fine to move as much code as possible to portable segment in order to reduce deplicates and bugs.

And I think one expect native JsType`s to be working for generic arguments. 

These ought to work.

public abstract class ArrayBuffer { ... }
@JsType(isNative = true, namespace = JsPackage.GLOBAL)


Yes and this is the problem I can not understand.
With the default name and name=ArrayBuffer the generic crashes in generated call to castToNative.
With name=Object the GWT does not generate type checking, instead it generates call to castToJsObject.

What am I doing wrong ?

And again, I hope using name=Object is not the best way to solve it. It looks like a hack to fool the GWT to avoid the crash.

Any suggestions ? 

Thanks

 
понедельник, 21 августа 2017 г., 17:06:26 UTC+3 пользователь Vassilis Virvilis написал:

Tony BenBrahim

unread,
Aug 21, 2017, 2:47:37 PM8/21/17
to google-we...@googlegroups.com
Take the object you get back from the file reader and run it through the JSNI method below and GWT,log the result. .Let's see if it really is an ArrayBuffer.(I would note the FileReader result is sometimes a String and sometimes an ArrayBuffer).
private native String getType(Object x)/*-{
    return Object.prototype.toString.call(x);
}-*/

--
You received this message because you are subscribed to a topic in the Google Groups "GWT Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/jiHnLPfUQhc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-toolkit+unsub...@googlegroups.com.

Kirill Prazdnikov

unread,
Aug 22, 2017, 8:02:49 AM8/22/17
to GWT Users
Here it is:

getType(buffer) = [object ArrayBuffer]
typeOf(buffer) = [object ArrayBuffer]

private native String getType(Object x) /*-{
return Object.prototype.toString.call(x);
}-*/;

private native String typeOf(Object x) /*-{
return typeof x;
}-*/;


понедельник, 21 августа 2017 г., 21:47:37 UTC+3 пользователь Tony BenBrahim написал:

Kirill Prazdnikov

unread,
Aug 22, 2017, 8:04:30 AM8/22/17
to GWT Users
Sorry, copypaster error, here is the fixed

getType(buffer) = [object ArrayBuffer]
typeOf(buffer) = object


вторник, 22 августа 2017 г., 15:02:49 UTC+3 пользователь Kirill Prazdnikov написал:

Vassilis Virvilis

unread,
Aug 22, 2017, 8:13:46 AM8/22/17
to google-we...@googlegroups.com
Kirill,

I am out of suggestions for but my curiosity drives me crazy.

What are you trying to do in java terms? For example:

  • Are you try to return an ArrayBuffer from a function: public <T> T getBuffer();
  • Are you try to pass an ArrayBuffer as a parameter: public <T> void sendBuffer(T buffer);
  • Are you try to put the ArrayBuffer in a List, Array, Set?
  • Something else?

I looked but I didn't find in the thread the description of the java caller that throws the exception.






--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsub...@googlegroups.com.

To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.



--
Vassilis Virvilis

Kirill Prazdnikov

unread,
Aug 22, 2017, 10:14:55 AM8/22/17
to GWT Users
I have a base class for drag and drop logic which looks something like this 

public abstract class FileDropHandler<FileT> extends InputClientAdapter {
 // here we have some common UI logic and constuctor
 // and the following methods are platform specific:
  protected abstract int length(FileT arrayBuffer);
  protected abstract Async<String> doUpload(FileT arrayBuffer);
protected abstract void processFile(DropEvent<?> dropEvent, MouseEvent mouseEvent);
protected abstract ObjectFactory[] loadObjects(String file, FileT arrayBuffer);
}

So in case of web, FileT is ArrayBuffer which I get form dropEvent.file, which is a web File type used in drag events.

public class FileDropHandlerGwt extends FileDropHandler<ArrayBuffer> { ... };

For JVM version I have regular files so I use java.io.File for the template argument. 
public class FileDropHandlerJvm extends FileDropHandler<File> { ... };

And this does not work for me. 
As a workaround I currently have a class container for ArrayBuffer like

static class ArrayBufferContainer { public final ArrayBuffer buffer; };

which I use for template argument currently. 

I think that there is a way to use ArrayBuffer directly, But I have not found a way to do that.
In order to understand GWT and understand JS-interop I`m asking this here.


Thanks
 -Kirill

вторник, 22 августа 2017 г., 15:13:46 UTC+3 пользователь Vassilis Virvilis написал:

Thomas Broyer

unread,
Aug 22, 2017, 11:08:55 AM8/22/17
to GWT Users
Could it possibly be that the ArrayBuffer is coming from another browsing context? (iframe)
What would the following output?

private native boolean isInstanceOfArrayBuffer(Object x) /*-{
  return x instanceof $wnd.ArrayBuffer;
}-*/;

Kirill Prazdnikov

unread,
Aug 22, 2017, 12:59:05 PM8/22/17
to GWT Users

Could it possibly be that the ArrayBuffer is coming from another browsing context? (iframe)

The isInstanceOfArrayBuffer returns false.

But the the crash happnes here: handleJetFile calls to getLength, then getLength at the entry calls to com.google.gwt....Cast.castToNative(src), without the second arg (jsType)

public abstract class FileDropHandler<FileT> extends InputClientAdapter {
  protected abstract int getLength(FileT buffer);
  protected void handleJetFile(final String file, final FileT buffer) {
Logger.log("Handle jet file. length = " + getLength(buffer));
    ....
     }
}

public class FileDropHandlerGwt extends FileDropHandler<ArrayBuffer> {
  ...
  @Override
protected int getLength(ArrayBuffer buffer) {
return buffer.getByteLength();
}
}


вторник, 22 августа 2017 г., 18:08:55 UTC+3 пользователь Thomas Broyer написал:

Thomas Broyer

unread,
Aug 22, 2017, 2:02:52 PM8/22/17
to GWT Users
If isInstanceOfArrayBuffer is false, then this is likely the root issue. And using name="Object" or name="?" is likely the only workaround until you can fix the ArrayBuffer provenance.

Kirill Prazdnikov

unread,
Aug 22, 2017, 2:25:27 PM8/22/17
to GWT Users

Thomas Broyer

unread,
Aug 22, 2017, 2:28:46 PM8/22/17
to GWT Users
Is the FileReader "instanceof $wnd.FileReader"? (Walk up the chain)

Vassilis Virvilis

unread,
Aug 23, 2017, 7:22:44 AM8/23/17
to google-we...@googlegroups.com
I think Thomas means how do you get the ArrayBuffer.You said from the FileReader but

How FileReader is created at the first place? I mean Is the script that returns the FileReader loaded by
  1. your GWT script? If which option did you use ScriptInjector. If yes - did you setWindow?
  2. the host html page where your GWT script is loaded?
Documentation says:

File objects may be obtained from a FileList object returned as a result of a user selecting files using the <input> element, from a drag and drop operation's DataTransfer object, or from the mozGetAsFile() API on an HTMLCanvasElement.

What happens if you put package name as $wnd?
@JsType(isNative = true, namespace = "$wnd")

    Vassilis




On Tue, Aug 22, 2017 at 9:28 PM, Thomas Broyer <t.br...@gmail.com> wrote:
Is the FileReader "instanceof $wnd.FileReader"? (Walk up the chain)

--

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsub...@googlegroups.com.

To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.



--
Vassilis Virvilis

Kirill Prazdnikov

unread,
Aug 23, 2017, 7:29:51 AM8/23/17
to GWT Users
Is the FileReader "instanceof $wnd.FileReader"? (Walk up the chain)

What is interesting, FileReader created with JSNI is not isInstanceOfFileReader, 

public static native FileReader newFileReader() /*-{
return new FileReader();
}-*/;

but FileReader created with jsType and jsConstructor is isInstanceOfFileReader

 @JsType(isNative = truepublic class FileReader { public FileReader() {} };

  isInstanceOfFileReader(fileReader) = true
  isInstanceOfFileReader(fileReader2) = false

The same for ArrayBuffer, one created with JSNI not a buffer passing isInstanceOfArrayBuffer, but one created with "new ArrayBuffer(10)" form java is passing isInstanceOfArrayBuffer.

Both FileReaders can read files and both ArrayBuffer returned form reading IS NOT passing isInstanceOfArrayBuffer.

If isInstanceOfArrayBuffer is false, then this is likely the root issue

Then I created a "good" ArrayBuffer (by java call new to JsConstructor). 
And copyed content of files` "bad" buffer (not passing isInstanceOfArrayBuffer) to good one (that passing isInstanceOfArrayBuffer). And then send the new buffer to the old crashing generic function :

ArrayBuffer arrayBuffer = fileReader2.resultArrayBuffer();
Logger.log("instanceOfArrayBuffer for file = " + isInstanceOfArrayBuffer(arrayBuffer));
ArrayBuffer good = new ArrayBuffer(arrayBuffer.getByteLength());
new Int8Array(good).set(new Int8Array(arrayBuffer));
Logger.log("instanceOfArrayBuffer for good copy = " + isInstanceOfArrayBuffer(good));
handleJetFile(name, arrayBuffer);


It is still craching in the same location.

    instanceOfArrayBuffer for file = false
    instanceOfArrayBuffer for good copy = true
 Uncaught Error: java.lang.ClassCastException 

Any suggestions ? 

Thanks
 

Kirill Prazdnikov

unread,
Aug 23, 2017, 7:36:28 AM8/23/17
to GWT Users
ArrayBuffer arrayBuffer = fileReader2.resultArrayBuffer();
Logger.log("instanceOfArrayBuffer for file = " + isInstanceOfArrayBuffer(arrayBuffer));
ArrayBuffer good = new ArrayBuffer(arrayBuffer.getByteLength());
new Int8Array(good).set(new Int8Array(arrayBuffer));
Logger.log("instanceOfArrayBuffer for good copy = " + isInstanceOfArrayBuffer(good));
handleJetFile(name, arrayBuffer);

Oh, my bad, that was the typo, should be 

handleJetFile(name, good); 

Now it works. Oh magic. GWT rtti is a hard rock.

I think I do not need to have two buffers to workaround that issue. (better to box_
Also I do not want to make a copy of all JsType classes, one with "name = Object" and other with good names. 
The best would be still to use a boxing class.

-Kirill
 
 

Kirill Prazdnikov

unread,
Aug 23, 2017, 8:15:32 AM8/23/17
to GWT Users
    instanceOfArrayBuffer for file = false
    instanceOfArrayBuffer for good copy = true
 Uncaught Error: java.lang.ClassCastException 

I think that it is a problem for generics. 
GWT will fail its checkcast for any instance of system type (like array buffer or whatever) for any class created other in any context other then $wnd.

JS "new ArrayBuffer(10)" and "new $wnd.ArrayBuffer(10)" has different type from GWT point of view.

Then my next question: 

if GWT generates checkckast as "yze_g$(fileBuffer_0_g$, $wnd.ArrayBuffer)",  where "$wnd.ArrayBuffer" is a type
how can I ask GWT to generate checkckast  to ArrayBuffer, not to $wnd.ArrayBuffer ? 

Thanks 

Kirill Prazdnikov

unread,
Aug 23, 2017, 8:17:21 AM8/23/17
to GWT Users
  1. your GWT script? If which option did you use ScriptInjector. If yes - did you setWindow?
Yes this is all our GWT script, nothing extra.

Tony BenBrahim

unread,
Aug 23, 2017, 8:17:22 AM8/23/17
to google-we...@googlegroups.com
public static native FileReader newFileReader() /*-{
    return new $wnd.FileReader();
}-*/;

 
 

--

Thomas Broyer

unread,
Aug 23, 2017, 8:30:27 AM8/23/17
to GWT Users


On Wednesday, August 23, 2017 at 1:29:51 PM UTC+2, Kirill Prazdnikov wrote:
Is the FileReader "instanceof $wnd.FileReader"? (Walk up the chain)

What is interesting, FileReader created with JSNI is not isInstanceOfFileReader, 

public static native FileReader newFileReader() /*-{
return new FileReader();
}-*/;

but FileReader created with jsType and jsConstructor is isInstanceOfFileReader

 @JsType(isNative = truepublic class FileReader { public FileReader() {} };

  isInstanceOfFileReader(fileReader) = true
  isInstanceOfFileReader(fileReader2) = false

The same for ArrayBuffer, one created with JSNI not a buffer passing isInstanceOfArrayBuffer, but one created with "new ArrayBuffer(10)" form java is passing isInstanceOfArrayBuffer.

Both FileReaders can read files and both ArrayBuffer returned form reading IS NOT passing isInstanceOfArrayBuffer.

Using your JSNI above, the objects are created in an iframe (the one the *.nocache.js creates and then loads *.cache.js into); the ones from JsInterop are (correctly/expectedly) created in the HTML host page.
As Tony said, use $wnd.FileReader rather than FileReader (or better yet, use JsInterop).

Kirill Prazdnikov

unread,
Aug 23, 2017, 8:31:20 AM8/23/17
to GWT Users
public static native FileReader newFileReader() /*-{
return new $wnd.FileReader();
}-*/;

This will not help, fileReader.resultArrayBuffer()returns not a instance of $wnd.ArrayBuffer anyway.

Thomas Broyer

unread,
Aug 23, 2017, 8:40:41 AM8/23/17
to GWT Users


On Wednesday, August 23, 2017 at 2:15:32 PM UTC+2, Kirill Prazdnikov wrote:
    instanceOfArrayBuffer for file = false
    instanceOfArrayBuffer for good copy = true
 Uncaught Error: java.lang.ClassCastException 

I think that it is a problem for generics. 
GWT will fail its checkcast for any instance of system type (like array buffer or whatever) for any class created other in any context other then $wnd.

JS "new ArrayBuffer(10)" and "new $wnd.ArrayBuffer(10)" has different type from GWT point of view.

From JS point of view: https://jsfiddle.net/aom01v1o/
 

Then my next question: 

if GWT generates checkckast as "yze_g$(fileBuffer_0_g$, $wnd.ArrayBuffer)",  where "$wnd.ArrayBuffer" is a type
how can I ask GWT to generate checkckast  to ArrayBuffer, not to $wnd.ArrayBuffer ?

In case you really need to reference a type in GWT's hidden iframe, then you can use namespace="<window>" instead of namespace=GLOBAL; but this is undocumented behavior that could possibly change or break at any time.
Better fix you JSNI to use $wnd, or use JsInterop all the way down, with namespace=GLOBAL.

Kirill Prazdnikov

unread,
Aug 23, 2017, 9:02:08 AM8/23/17
to GWT Users


Then my next question: 

if GWT generates checkckast as "yze_g$(fileBuffer_0_g$, $wnd.ArrayBuffer)",  where "$wnd.ArrayBuffer" is a type
how can I ask GWT to generate checkckast  to ArrayBuffer, not to $wnd.ArrayBuffer ?

In case you really need to reference a type in GWT's hidden iframe, then you can use namespace="<window>" instead of namespace=GLOBAL;

No, I want reference to a global type.
 
but this is undocumented behavior that could possibly change or break at any time.
Better fix you JSNI to use $wnd, or use JsInterop all the way down, with namespace=GLOBAL.

Why with namespace=GLOBAL  gwt generates checks that type is $wnd.ArrayBuffer ?

Thomas Broyer

unread,
Aug 23, 2017, 9:33:06 AM8/23/17
to GWT Users
Ouch! You're unfortunately right: https://jsfiddle.net/wuvbnpz6/1/
…at least in Chrome; because Firefox works as intended!
Please report the bug at https://crbug.com (if no-one did already), and in the mean time, use name="Object", or possibly use a Java interface rather than a class.

Thomas Broyer

unread,
Aug 23, 2017, 9:35:06 AM8/23/17
to GWT Users


On Wednesday, August 23, 2017 at 3:02:08 PM UTC+2, Kirill Prazdnikov wrote:


Then my next question: 

if GWT generates checkckast as "yze_g$(fileBuffer_0_g$, $wnd.ArrayBuffer)",  where "$wnd.ArrayBuffer" is a type
how can I ask GWT to generate checkckast  to ArrayBuffer, not to $wnd.ArrayBuffer ?

In case you really need to reference a type in GWT's hidden iframe, then you can use namespace="<window>" instead of namespace=GLOBAL;

No, I want reference to a global type.

Terminology confusion here.
 
but this is undocumented behavior that could possibly change or break at any time.
Better fix you JSNI to use $wnd, or use JsInterop all the way down, with namespace=GLOBAL.

Why with namespace=GLOBAL  gwt generates checks that type is $wnd.ArrayBuffer ?

Because that's what GLOBAL means, which is what you want 99.9% of the time (except when you find a bug in Chrome that returns an object from the current browsing context rather than the one from the originating object)
 

Vassilis Virvilis

unread,
Aug 23, 2017, 9:44:00 AM8/23/17
to google-we...@googlegroups.com
Wow!

Isn't this somewhat serious? It looks that it bypass the browser's security model, XSS and all that...

That was one fascinating thread to watch.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsub...@googlegroups.com.

To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.



--
Vassilis Virvilis

Kirill Prazdnikov

unread,
Aug 24, 2017, 11:50:02 AM8/24/17
to GWT Users
Reply all
Reply to author
Forward
0 new messages