Be careful of discrepancy between the GWT development mode and production mode

We spend most of our development time running our application in development mode, which means that we are interacting with our GWT application without it having been translated into JavaScript.

Anytime we edit, run, and debug applications from a Java integrated development environment (IDE), we are working in development mode. When an application is running in development mode, the Java Virtual Machine (JVM) is actually executing the application code as compiled Java bytecode, using GWT plumbing to connect to a browser window. This means that the debugging facilities of our IDE are available to debug both our client-side GWT code and any server-side Java code as well.

For 99.99% percent of the time, the development mode is perfect mirror to the production mode.

I come across the 0.01% recently.

If you have a java.util.Date object in the GWT client code, when development mode, it is a java Date while in production mode it is a javascript date.

In java, it supports dates between Long.MIN_VALUE and Long.MAX_VALUE:

class DateTest {
    public static void main(String[] args) {
        DateFormat df = new SimpleDateFormat("d MMM yyyy G, HH:mm:ss.S Z");

        System.out.println(df.format(new Date(Long.MIN_VALUE)));
        System.out.println(df.format(new Date(0)));
        System.out.println(df.format(new Date(Long.MAX_VALUE)));


2 Dec 292269055 BC, 10:47:04.192 -0600
31 Dec 1969 AD, 18:00:00.0 -0600
17 Aug 292278994 AD, 01:12:55.807 -0600

However when it comes to javascript:

1. This works on all major version browsers:

 var d = new Date();


Fri Sep 12 275760 20:00:00 GMT-0400 (Eastern Daylight Time)

2. This does not work:

 var d = new Date();

Outputs: Invalid date.


As a result, in development mode a date after js limit  like 09/12/275761 will be a valid one while in the production mode it is not.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s