简体   繁体   中英

Google App Engine - InvalidClassException when logging in

I'm using a custom class UserProfile to manage my sessions in Google app engine and i get the error (when users access the app's default servlet):

javax.servlet.ServletException: java.lang.RuntimeException: java.io.InvalidClassException: ro.expert.evt.shared.entities.ObjectModel; local class incompatible: 
stream classdesc serialVersionUID = -2824144882306533912, 
local class serialVersionUID = 6500787607817458947

I know the problem is that I updated my class and when I deployed my app it did not have a serialVersionUID.

My questions are:

  1. If I set a generated serialVersionUID will the problem appear again ? do I have do regenerate it every time I modify my user class ?

  2. How do I fix this for my already logged in users ? How do I invalidate their sessions ("clearing" their cookies should work )

Edit: Would clearing the whole memcache invalidate the users sessions ?

I should call getSession().invalidate() but i cannot run any code to catch the exception:

Caused by: java.lang.RuntimeException: java.io.InvalidClassException: ro.expert.evt.shared.entities.ObjectModel; local class incompatible: stream classdesc serialVersionUID = -2824144882306533912, local class serialVersionUID = 6500787607817458947
    at com.google.apphosting.runtime.SessionManagerUtil.deserialize(SessionManagerUtil.java:57)
    at com.google.apphosting.runtime.jetty.MemcacheSessionStore.getSession(MemcacheSessionStore.java:39)
    at com.google.apphosting.runtime.jetty.SessionManager.loadSession(SessionManager.java:327)
    at com.google.apphosting.runtime.jetty.SessionManager.getSession(SessionManager.java:301)
    at org.mortbay.jetty.servlet.AbstractSessionManager.getHttpSession(AbstractSessionManager.java:237)
    at org.mortbay.jetty.servlet.SessionHandler.setRequestedId(SessionHandler.java:246)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:136)
    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:266)
... 16 more

Is there a method in my initial servlet that i can override so that i can catch the exception above and invalidate the user's session ?

Yes you have to provide explicit serialVersionUID value to avoid this error. You can keep value the same between deployments or/and class modifications.

As for existing users you can use versioning feature of GAE. Deploy with increased version, eg existing GAE app v. 1 so deploy new code as v.2 and then you can repoint default version to your new version...so existing users will still keep using old version...but new ones will hit new ver.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM