1

I have been playing around with GWT, and I seem to have the bad habit of creating classes that don't meet the rule for GWT serializable objects:

A user-defined class is serializable if all of the following apply:

  • It is assignable to IsSerializable or Serializable, either because it directly implements one of these interfaces or because it derives from a superclass that does
  • All non-final, non-transient instance fields are themselves serializable, and
  • As of GWT 1.5, it must have a default (zero argument) constructor (with any access modifier) or no constructor at all.

Usually I forget to include a default constructor. I normally find out about this when I get a a serialization exception at runtime. This strikes me as unnecessary. Surely there is some way that Eclipse (or the Google Plugin) can statically analyze my GWT code and discover this screw up at compile time? Seeing a little red squiggly somewhere is infinitely nicer than getting a runtime exception.

I am hoping for a solution like one of the following, in increasing order of desire:

  • Config option I can set in Eclipse or the Google Plugin to enable this kind of warning/validation
  • Additional plugin I can install that would do this
  • Any other preexisting way to get the job done.
  • Hints on how I could modify the Google Plugin to do this myself.
Peter Recore
  • 14,037
  • 4
  • 42
  • 62
  • So you create a parameterized constructor, but forget to create an public empty one? I haven't seen a plugin that would help you out. It's not a compilation problem, even if the class implements Serializable. – Vladimir Dec 16 '11 at 06:37
  • @Vladimir, You are correct in that the code does compile. However, there is plenty of static analysis that can be done that doesn't relate to whether code actually compiles. Tools like findbugs, checkstyle, and others all help people identify runtime bugs at compile time. It seems eminently reasonable to expect that one could write a tool to detect the scenario of "A class implements gwt's IsSerializeable interface but does not have a default constructor" (as an aside, I usually make it private as I don't want to ever call it myself. GWT doesn't care what access modifier it has) – Peter Recore Dec 19 '11 at 18:46

1 Answers1

1

Don't know exact answer but I would try to see if checkstyle can do that. It can be invoked from build (ant/maven) and there is also Eclipse plugin. If there are no default check like this I think it could be added reasonably easy.

maximdim
  • 8,041
  • 3
  • 33
  • 48