grails-cookie-session icon indicating copy to clipboard operation
grails-cookie-session copied to clipboard

Cannot cast com.esotericsoftware.shaded...StdInstantiatorStrategy to InstantiatorStrategy

Open tobia opened this issue 9 years ago • 2 comments

I cannot get kryo to work, I get this exception when hitting any page:

Message: Cannot cast object 'com.esotericsoftware.shaded.org.objenesis.strategy.StdInstantiatorStrategy@3f0f64c2' with class 'com.esotericsoftware.shaded.org.objenesis.strategy.StdInstantiatorStrategy' to class 'org.objenesis.strategy.InstantiatorStrategy'
    Line | Method
->>  154 | getConfiguredKryoSerializer in com.granicus.grails.plugins.cookiesession.KryoSessionSerializer
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     70 | serialize                   in     ''
|    369 | serializeSession . . . . .  in com.granicus.grails.plugins.cookiesession.CookieSessionRepository
|    354 | saveSession                 in     ''
|     95 | saveSession . . . . . . . . in com.granicus.grails.plugins.cookiesession.SessionRepositoryResponseWrapper
|    136 | sendRedirect                in     ''
|     62 | commence . . . . . . . . .  in grails.plugin.springsecurity.web.authentication.AjaxAwareAuthenticationEntryPoint
|     53 | doFilter                    in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
|     49 | doFilter . . . . . . . . .  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter                    in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|     84 | doFilterInternal . . . . .  in com.granicus.grails.plugins.cookiesession.CookieSessionFilter
|   1145 | runWorker                   in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run                         in java.lang.Thread

I'm using Grails 2.4.4, cookie-session 2.0.17, the latest Kryo 3.0.1, spring-security-core 2.0-RC4 and the relevant cookie setting. I can run more tests to pinpoint the issue, or I can provide a minimal Grails app that shows the problem, if needed. I also tried the kryo-shaded release, same error.

Am I doing something wrong?

PS: Thank you for your work on cookie-session. I cannot believe this is not the default in the J2EE world! People are putting session data in the DB, in memcached, in MongoDB… it's crazy! You may want to put a prominent link to some article about the fundamental REST philosophy of the web, such as this great one, that clearly shows that application state belongs to the client, as opposed to resource state.

tobia avatar Apr 10 '15 11:04 tobia

So the issue is that the latest version of kryo and the supplemental kryo-serializer package aren't compatible - namespaces changed and a few other things from what I can tell. I tried to upgrade kryo recently and ran into all sorts of trouble. I'll try again once everything is worked out between the two.

In any case, you don't need to import the kryo package directly - the cookie-session plugin brings in the appropriate version to your project. Remove your kryo dependency and it should work fine... you may need to clean your package to get rid of remnants of the latest version of kryo by deleting the target directory in your project.

Try this and let me know how it goes.

FYI - kryo is a pretty good serializer, but it isn't perfect and I've run into many objects (flash object name one) that aren't serializable by simple field inspection and have necessitated writing custom object serializers. In general though, out of the box grails and spring security should work fine.

I'm glad you like the plugin. thanks :)

benlucchesi avatar Apr 14 '15 04:04 benlucchesi

Fixed in https://github.com/double16/grails-cookie-session/tree/release/4.0.0

dependencies { compile 'org.grails.plugins:cookie-session:4.0.0.RC1' }

double16 avatar Oct 19 '17 16:10 double16