Friday, April 17, 2009

Field Initialisation in Google App Engine

Had a weird problem that took a while to resolve. I'm still not sure what the issue really was, perhaps its a problem with GAE itself. Here are the details:

I have a class that is packaged within a Jar and included in the applications WEB-INF/lib directory.

I was struggling with the following errors:

javax.servlet.ServletException: [Ljava.lang.String;
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:239)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:313)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830)
at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:63)
...

Nested in javax.servlet.ServletException: [Ljava.lang.String;
:java.lang.ArrayStoreException: [Ljava.lang.String;
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
...

The class I was using has an instance field initialised as:
private SimpleDateFormat sdf = new SimpleDateFormat("MMddyyHHmmssSSS");

If I remove the field initialisation and initialise the field in a method, then all works fine.

I'm not sure what the problem is, it works fine under Tomcat, but is there some instance field initialisation issue within GAE? Or is it just SimpleDateFormat has a problem, perhaps a locale issue?

Anyway, thought I'd post it here as it took a lot of trial and error to find this issue. It may save someone else the time.

If there's an 'real' answer to the problem then it may appear here.

No comments:

Post a Comment