Debug ClassCastException in client-side connector initialization

Hi,

I am trying to find the cause for a ClassCastException inside a Vaadin 7.2.6 application. The SuperDevMode provided me with this stacktrace:

SEVERE: java.lang.ClassCastException at Unknown.fillInStackTrace_0(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@23:3523) at Unknown.fillInStackTrace(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@10:2546) at Unknown.Throwable(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@8:2518) at Unknown.Exception(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@16:2569) at Unknown.RuntimeException(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@16:2593) at Unknown.ClassCastException(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@23:92172) at Unknown.dynamicCast(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@11:13559) at Unknown.$deserialize(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@54:36085) at Unknown.deserialize(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@15:36099) at Unknown.decodeObject(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@27:36391) at Unknown.decodeValue(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@1719:36478) at Unknown.decodeObject(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@29:36412) at Unknown.decodeValue(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@1719:36478) at Unknown.decodeIntoCollection(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@23:36355) at Unknown.decodeList(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@8:36362) at Unknown.decodeValue(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@1719:36478) at Unknown.decodeObject(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@29:36412) at Unknown.decodeValue(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@1719:36478) at Unknown.$updateConnectorState(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@14:28264) at Unknown.execute_22(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@34:28369) at Unknown.endDependencyLoading(http://localhost:9876/vaadin.AppWidgetSet/5601E60412064200647F380440CB4188.cache.js@11:26393) ... So it seems some state object cannot be deserialized correctly in the Javascript-version of ApplicationConnection.java.

How can I find out which object is causing this? I tried activating the profiler to get a bit more information about which connector blows up, but I can’t see any profiler messages in the Javascript/Debug console, besides this:

com.vaadin.client.Profiler SEVERE: Got end event for updateConnectorState but is currently in JsonDecoder.decodeObject What is the best way to see what data causes the exception? My Javascript debugging skills are a bit lacking… Inside the Chrome debugger all the interesting values seem to be undefined when stepping through updateConnectorState.

Any hints are greatly appreciated!

Ok, using Chrome instead of Chrome Portable helps a lot with debugging…

So the ClassCastException occurs when calling this:

return new ju.Date_3(fromDouble(cggjc.$doubleValue([b] dynamicCast(jsonValue, 126) [/b]))) where jsonValue is an Object describing a date (see attachment). This is in the Date_Serializer which expects a number, but receives an Object.

It seems the serialization of the date doesn’t turn the date into a number?

16729.png

The JSON received from the server indeed contains an object instead of a number:

{..., "bandInfos":[{"date":{"date":1,"hours":0,"seconds":0,"month":6,"year":114,"minutes":0,"time":1404165600000}, ...}]
, ...}

Any ideas?
Cheers!

Alright, I found the culprit.

The “date” in the state came directly from a database… turns out it isn’t a java.util.Date but a java.sql.Timestamp.

The customSerializers in
https://github.com/vaadin/vaadin/blob/cf77a27c7f711e076c4f2c47cca46d87111bdb15/server/src/com/vaadin/server/JsonCodec.java#L217

expect an actual Date, not a subclass.

Would be great if you can make it work for subclasses as well, because currently the behavior is quite unexpected.

Atleast it should handle the common subclasses java.sql.Date and Timestamp or minimally, when not compiled for production, serialization should throw an error.