Play 2.2.0: Can't load Nashorn script engine with Play classloader

126 views
Skip to first unread message

Chris Pettitt

unread,
Apr 16, 2014, 11:20:03 AM4/16/14
to play-fr...@googlegroups.com
Hi,

I'm trying to use Nashorn in Play 2.2.0 (dev mode), but if I use the Play classloader (Play.application.classloader, or Thread.currentThread.getContextClassLoader() for the thread running a Controller) it cannot be found. If I switch to the system classloader (ClassLoader.getSystemClassLoader()), I am able to load Nashorn successfully. I don't like this option though, because it is possible to leak the Play classloader if we have another GC root pointing at stuff it has loaded.

Any ideas?

Thanks,
Chris

Sebas

unread,
May 6, 2014, 1:26:50 PM5/6/14
to play-fr...@googlegroups.com
Hi Chris,

I have ran into the same problem as you. Using Play 2.2.3, this problem still exists.

Some googling around brought me to https://github.com/playframework/playframework/issues/2532, so the problem is know, but 'solved' by saying you have to pass null to the constructor (this actually works).

Problem I found is that a library i'm using is calling the ScriptEngineManager, so I have no direct control over it.

Tested the same code with jdk 1.7, and found that the code worked fine without any modifications to the constructor.

It would be nice if this bug could get re-opened since it shows that something changed and play is not playing along with those changes (perhaps this is the first time somebody noticed it, who knows what else is broken).

Hope to see some replies from play developers, lots of info on how to reproduce it is in the issue tracker at github, but the most basic test is:

ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("javascript");
result -> engine = null

ScriptEngineManager factory = new ScriptEngineManager(null);
ScriptEngine engine = factory.getEngineByName("javascript");
result -> engine is nashorn

ScriptEngineManager factory = new ScriptEngineManager(Play.application().classloader());
ScriptEngine engine = factory.getEngineByName("javascript");
result -> engine = null

ScriptEngineManager factory = new ScriptEngineManager(Play.class.getClassLoader());
ScriptEngine engine = factory.getEngineByName("javascript");
result -> engine = null

Sebas
Reply all
Reply to author
Forward
0 new messages