0

I am getting many errors when i try to compile my GWT application. Some of them are

[ERROR] com.google.gwt.xml.client.impl.AttrImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. 
              [ERROR] com.google.gwt.xml.client.impl.CDATASectionImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. 
              [ERROR] com.google.gwt.xml.client.impl.CommentImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
              [ERROR] com.google.gwt.xml.client.impl.DocumentFragmentImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
              [ERROR] com.google.gwt.xml.client.impl.DocumentImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. 
              [ERROR] com.google.gwt.xml.client.impl.ElementImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
              [ERROR] com.google.gwt.xml.client.impl.EntityReferenceImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. 
              [ERROR] com.google.gwt.xml.client.impl.NamedNodeMapImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
              [ERROR] com.google.gwt.xml.client.impl.NodeImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. 
              [ERROR] com.google.gwt.xml.client.impl.NodeListImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. 
              [ERROR] com.google.gwt.xml.client.impl.ProcessingInstructionImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. 
              [ERROR] com.google.gwt.xml.client.impl.TextImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. 
              [ERROR] java.util.AbstractList.SubList<E> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. 
              [ERROR] java.util.AbstractList.SubList<E> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
              [ERROR] java.util.Collections.UnmodifiableList<T> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
              [ERROR] java.util.Collections.UnmodifiableList<T> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. 
              [ERROR] java.util.Collections.UnmodifiableRandomAccessList<T> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. 
              [ERROR] java.util.Collections.UnmodifiableRandomAccessList<T> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
              [ERROR] java.util.LinkedList.Node<E> is not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' or 'java.io.Serializable' nor does it have a custom field serializer 
              [ERROR] java.util.LinkedList.Node<E> has no available instantiable subtypes. 
              [ERROR]    subtype java.util.LinkedList.Node<E> is not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' or 'java.io.Serializable' nor does it have a custom field serializer 

I get this error in my client side code ! From whatever i could read from the internet , it says i simply cannot emulate all of the standard methods that run in an JRE container to GWT because it will be compiled to Javascript at runtime . But i'm too inexperienced to understand this error. Would appreciate any help regarding this!

Ozair Kafray
  • 13,351
  • 8
  • 59
  • 84
Napster
  • 157
  • 3
  • 17

2 Answers2

1

Three maxims:

  • GWT Java is Java but not Java
  • GWT Java is actually Java-compiler-friendly Javascript.
  • Implementing Serializable may not be GWT Serializable

Can anything be serialized as long as it implements Serializable?

In the java SE/EE bytecode world, serialization is simpler. In the following class declaration:

class Spider
implements Serializable{
  String a;
  Integer b;
  Cobweb c;
}

Compiler would sail thro a and b because, String already has its own serialization codec (i.e. coder/decoder or marshaller/demarshaller). So does Integer.

Compiler then tries to see if Cobweb implements Serializable either by providing its own codec or Cobweb comprises Serializable members like

class Cobweb 
implements Serializable{
  Boolean d;
  Double e;
}

Both d and e already have serialization codec provided by the courtesy of Sun/Oracle's stewardship of the Java language.

What if CobWeb allows generic arguments?

class Cobweb <T>
implements Serializable{
  Boolean d;
  T e;
}

Cobweb<Float> would be serializable because Java already has a serialization codec for Float.

However, unless Donkey has a custom serialization codec, the compiler would croak on the following

class Spider
implements Serializable{
  String a;
  Integer b;
  Cobweb<Donkey> c;
}

What does GWT serialable mean?

Isn't implementing Serializable enough? Why, is Google implementing a new Serializable interface? Nope. It is Google's fault but not Google's fault.

GWT UI Java is always compiled to Javascript before it can be run. The native code for GWT UI Java is Javascript not binary Java bytecode. For the plain and obvious reason that the browser runs only Javascript but not Java bytecode.

Binary Data and GWT

In most instances, implementing Serializable would make your class GWT serializable. Being GWT serializable means that there is GWT-generated Javascript code that exists to perform the codec when needed. i.e., the codec is in Java source not Java byte-code. The codec must be translatable to Javascript because the GWT serialization/deserialization runs on the browser.

However, there are many classes that GWT does not have a codec already. For example, GregorianCalender and most classes that require Reflection. GregorianCalender implements Serializable but GWT compiler does not have any codec for it in Java source code that can be translated into Javascript.

GWT-generated Javascript is incapable of run-time Reflection. So GWT compensates that deficiency by performing delayed binding of pre-compiled permutations of all possible code that you could use. I believe that GregorianCalendar performs some measure of Reflection and writing a GWT codec for GregorianCalendar would be too huge number of permutations of Javascript code. I believe that is the reason as well as is the reason for the absence of codec for many classes. Someone please correct me.

Back to the original question ....

java.util.LinkedList.Node<E>

So, for goodness' sake, what in the world is E? Did you substitute E with a GWT serializable?

Evidence from the stack trace (if I am even good at tracing a stack trace) indicates that you had not even bothered to substitute the generic argument with an actual type. By doing that, you are forcing GWT compiler to consider E as the class Object. And nobody knows how to serialize the class Object. You would be like the Pharaoh in Genesis 41 telling Joseph,

"Joseph please interpret my dream, but I have forgotten my dream, so you have to tell me about my dream too."

Community
  • 1
  • 1
Blessed Geek
  • 21,058
  • 23
  • 106
  • 176
0

As first line of stack says, to be serialized, class need to have constructor with no parameters or have custom serializer. java-custom-serialization here is topic about writing serializer

Community
  • 1
  • 1
T.G
  • 1,913
  • 1
  • 16
  • 29