Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Custom SessionStore throws ClassNotFoundException #1297

@pcavadas

Description

@pcavadas

Play Framework version: 1.5.2
OS: MacOS 10.14.3
IntelliJ IDEA 2018.3.5 (Ultimate Edition)
Google App Engine: 1.9.71
JDK: Oracle 1.8.0_201

java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

I have a Play 1.5 app running on Google App Engine Standard. I'm trying to customize my session store with this simple class:

package overrides;

import play.mvc.CookieSessionStore;

public class CustomCookieSessionStore extends CookieSessionStore {
}

And in my application.conf file:

application.session.storeClass=overrides.CustomCookieSessionStore

Everything runs fine when:

  • running the app from IntelliJ IDEA ("Application" configuration type, with play.server.Server as "Main class")

It fails when:

  • running the app from the command line with play run
  • building the app as an exploded war, and deploying it on an App Engine Standard server (both on the local App Engine development server and on Google's servers)

Here is the output of play run:

16:22:10,998 INFO  ~ Storing sessions using overrides.CustomCookieSessionStore
16:22:11,001 ERROR ~ Failed to handle invocation exception by plugin play.data.validation.ValidationPlugin
java.lang.NoClassDefFoundError: Could not initialize class play.mvc.Scope
	at play.data.validation.ValidationPlugin.clear(ValidationPlugin.java:192)
	at play.data.validation.ValidationPlugin.onInvocationException(ValidationPlugin.java:99)
	at play.plugins.PluginCollection.onInvocationException(PluginCollection.java:570)
	at play.Invoker$Invocation.onException(Invoker.java:266)
	at play.Invoker$Invocation.run(Invoker.java:334)
	at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:252)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
16:22:11,817 ERROR ~ 

@7b4dn7if3
Internal Server Error (500) for request GET /

Oops: ExceptionInInitializerError
Unexpected error : Unexpected Error, caused by exception ExceptionInInitializerError: null

play.exceptions.UnexpectedException: Unexpected Error
	at play.Invoker$Invocation.onException(Invoker.java:270)
	at play.Invoker$Invocation.run(Invoker.java:334)
	at Invocation.HTTP Request(Play!)
Caused by: java.lang.ExceptionInInitializerError
	at play.mvc.Scope$Session.restore(Scope.java:179)
	at play.mvc.ActionInvoker.initActionContext(ActionInvoker.java:102)
	at play.mvc.ActionInvoker.resolve(ActionInvoker.java:61)
	... 1 more
Caused by: play.exceptions.UnexpectedException: Cannot create instance of overrides.CustomCookieSessionStore
	at play.mvc.Scope.createSessionStore(Scope.java:49)
	at play.mvc.Scope.<clinit>(Scope.java:36)
	... 4 more
Caused by: java.lang.RuntimeException: Cannot instantiate overrides.CustomCookieSessionStore
	at play.inject.Injector.getBeanOfType(Injector.java:27)
	at play.mvc.Scope.createSessionStore(Scope.java:46)
	... 5 more
Caused by: java.lang.ClassNotFoundException: overrides.CustomCookieSessionStore
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at play.inject.Injector.getBeanOfType(Injector.java:25)
	... 6 more

The Injector class is trying to load CustomCookieSessionStore with this line:

return getBeanOfType((Class<T>) Class.forName(className));

In this case, Class.forName is using the classloader of the Injector class, which is not the same as Play.classloader. My custom class is present on Play.classloader, but not on Injector's.

Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions