Wednesday, August 23, 2017

Re: ClassCastException in generics

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 ? 


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
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment