Google Web ToolkitI ran into a cunning Google Web Toolkit JavaScript problem, related to the Java long data type. I was using long for my objects’ identities, that are persisted to db4o. On the server side the objects’ identities had the correct values. When I returned the object as a serialized XML string, the value was also correct. But as soon as I tried to directly use long, the value was always one less, than the actual value it was meant to be.

Before I decided on long for my object identities, I had a gut feeling that JavaScript might not support this data type. Turns out my original suspicion was valid: “Intrinsic types byte, char, short, int, long, float, double, Object, String, and
arrays are supported. However, there is no 64-bit integral type in JavaScript, so variables of type long are mapped onto JavaScript double-precision floating point values. To ensure maximum consistency between hosted mode and web mode, we recommend that you use int variables.”

It probably would be a good idea if the GWT compiler reported any long types as warnings. There’s no point having a long that doesn’t really work. It just opens the opportunity for problems like this one.

3 Responses to “Google Web Toolkit’s (GWT) Fake Long”


  1. Any chance you can contribute your app (or a sample) to projects.db4o.com?

    Best!

    German

  2. openlandscape Says:

    This is definitely planned. I’d like to flesh the project out a little bit more, before making it public. But I promise as soon as some key features have been completed, GhostBlade will be at projects.db4o.com!

  3. German Says:

    Nice thanks! You can reach me at german -AT – db4o.com
    Best regards!!
    German


Leave a Reply