GAE会议。 java.io.NotSerializableException:sun.nio.cs.UTF_8问题

时间:2011-10-04 17:18:48

标签: java google-app-engine session exception

我是Google App Engine的新手,在我第一次部署新应用程序时遇到了问题。 我试图在会话中存储一些对象。在我的localhost上一切正常。 下面的堆栈跟踪指向我不能序列化的“组”类 - 但它确实如此。希望有人能提供帮助。提前谢谢。

/CreateGroup.action
java.lang.RuntimeException: java.io.NotSerializableException: sun.nio.cs.UTF_8
    at com.google.apphosting.runtime.jetty.SessionManager.serialize(SessionManager.java:358)
    at com.google.apphosting.runtime.jetty.DatastoreSessionStore.createEntityForSession(DatastoreSessionStore.java:71)
    at com.google.apphosting.runtime.jetty.DatastoreSessionStore.saveSession(DatastoreSessionStore.java:93)
    at com.google.apphosting.runtime.jetty.SessionManager$AppEngineSession.save(SessionManager.java:153)
    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:249)
    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$RequestRunnable.run(JavaRuntime.java:391)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:160)
    at java.lang.Thread.run(Thread.java:679)
Caused by: java.io.NotSerializableException: sun.nio.cs.UTF_8
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
    at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:438)
    at com.xxxxxxxxx.xxxxxxxxx.model.Group.writeObject(Group.java)
    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:1480)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
    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:1480)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
    at com.google.apphosting.runtime.jetty.SessionManager.serialize(SessionManager.java:355)
    ... 23 more

Group.java有这些字段(CommonPool类型也在实现Serializable):

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Group implements Serializable {

    private static final long serialVersionUID = -5274228818084728571L;

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private String name;

    @Persistent
    private int memberCount;

    @Persistent
    private int maxMemberCount;

    @Persistent
    private String currencySymbol;

    @Persistent
    private String url;

    @Persistent
    private Date createdOn;

    @Persistent
    private CommonPool pool;

2 个答案:

答案 0 :(得分:2)

看起来你已经“覆盖”了神奇的writeObject方法来自定义Group的序列化方式,并且在某处有一个sun.nio.cs.UTF_8的实例。你说CommonPool是Serializable,但只是实现接口并没有这样做。它必须实际上是可序列化的,否则它将失败。那里还有一个“钥匙”。这也可能是你问题的根源。

答案 1 :(得分:1)

好的,所以我想出来了(我觉得有点尴尬) 在Group.java中有一个我忽略的字段(不在上面的代码存根中)并且不可序列化......愚蠢的我。 很抱歉给您带来不便,感谢Ryan的快速回复。