NotSerializableException

217 views
Skip to first unread message

Steve Fisher

unread,
May 17, 2011, 7:39:01 PM5/17/11
to google-a...@googlegroups.com
I have a small application (using GWT) which was working fine on my own machine but gives problems when I deploy it on GAE. I get a message about a NotSerializableException for a class defined as a public inner class of a another class on the server side. Instances of this class are associated with a session on the server by:

HttpServletRequest req = this.getThreadLocalRequest();
HttpSession sess = req.getSession();
UserInfo ui = (UserInfo) sess.getAttribute("UserInfo");

The rest of this message is the traceback. Any ideas please?

Steve

---------------------------------------------------------

 java.lang.RuntimeException: java.io.NotSerializableException: uk.org.harwellcroquet.server.LoginServiceImpl$UserInfo
	at com.google.apphosting.runtime.jetty.SessionManager.serialize(SessionManager.java:393)
	at com.google.apphosting.runtime.jetty.SessionManager.createEntityForSession(SessionManager.java:370)
	at com.google.apphosting.runtime.jetty.SessionManager$AppEngineSession.save(SessionManager.java:164)
	at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:41)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
	at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
	at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:238)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
	at org.mortbay.jetty.Server.handle(Server.java:326)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
	at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
	at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:135)
	at com.google.apphosting.runtime.JavaRuntime.handleRequest(JavaRuntime.java:260)
	at com.google.apphosting.base.RuntimePb$EvaluationRuntime$2.handleRequest(RuntimePb.java:9669)
	at com.google.net.rpc.impl.RpcUtil.runRpcInApplication(RpcUtil.java:439)
	at com.google.net.rpc.impl.Server$RpcTask.runInContext(Server.java:573)
	at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:448)
	at com.google.tracing.TraceContext.runInContext(TraceContext.java:688)
	at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:326)
	at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:318)
	at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:446)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:636)
Caused by: java.io.NotSerializableException: uk.org.harwellcroquet.server.LoginServiceImpl$UserInfo
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1173)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:343)
	at java.util.HashMap.writeObject(HashMap.java:1018)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:962)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1478)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1409)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1167)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:343)
	at com.google.apphosting.runtime.jetty.SessionManager.serialize(SessionManager.java:390)
	... 31 more

Stephen Johnson

unread,
May 17, 2011, 8:40:43 PM5/17/11
to google-a...@googlegroups.com
You need to make sure that the class implements the
java.io.Serializable interface. There are no methods to this
interface:

class MyClass implements java.io.Serializable {

}

Stephen

> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to google-a...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengi...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>

Brandon Donnelson

unread,
May 17, 2011, 10:58:04 PM5/17/11
to google-a...@googlegroups.com
Stephen is correct. You won't be able to use some classes since they don't know how to translate into javascript. What I do is setup a class for data transport, to go between GAE and GWT front end.

Brandon Donnelson

Jeff Schnitzer

unread,
May 18, 2011, 4:52:14 AM5/18/11
to google-a...@googlegroups.com
Also make sure your inner class is a static inner class, otherwise it
will try to serialize the containing object too.

Jeff

Steve Fisher

unread,
May 18, 2011, 3:29:51 PM5/18/11
to Google App Engine
Hi,

I have now moved the inner class to being in a file of its own - and
added the implements java.io.Serializable but have not added a
constructor without arguments and now it is working. This is good.
However nowhere in the client code is this class referenced it is only
used on the server side so why was it being serialized and why did it
work on my own machine but not after it had been deployed?

Steve

Stephen Johnson

unread,
May 18, 2011, 4:45:05 PM5/18/11
to google-a...@googlegroups.com
If u store objects in the Session they must be serializable because
this data gets saved to the datastore in _ah_session so that it can be
shared across multiple instances, etc. However the dev server doesn't
need to do this since it's only one machine and it keeps the session
info in memory so since it's never serialized the dev server never
complains.

Sent from my iPhone

On May 18, 2011, at 12:29 PM, Steve Fisher <dr.s.m...@gmail.com>
wrote:

> Hi,

> appe...@googlegroups.com.

Steve Fisher

unread,
May 18, 2011, 7:41:37 PM5/18/11
to google-a...@googlegroups.com
Stephen,

Thanks for the explanation

Steve

>> To post to this group, send email to google-a...@googlegroups.com.


>> To unsubscribe from this group, send email to
>> google-appengi...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/google-appengine?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.

> To post to this group, send email to google-a...@googlegroups.com.

Stephen Johnson

unread,
May 18, 2011, 10:13:59 PM5/18/11
to google-a...@googlegroups.com
Your welcome.
Reply all
Reply to author
Forward
0 new messages