Project

General

Profile

Bug #1898

Definitions cannot be loaded

Added by Luke Murphey over 7 years ago. Updated over 7 years ago.

Status:
New
Priority:
Normal
Assignee:
Category:
Scan Engine
Target version:
Start date:
06/07/2017
Due date:
% Done:

0%


Description

java.lang.NoClassDefFoundError: sun/org/mozilla/javascript/internal/Context
net.lukemurphey.nsia.scan.ScriptDefinition.getScriptEngine(ScriptDefinition.java:162) at net.lukemurphey.nsia.scan.ScriptDefinition.<init>(ScriptDefinition.java:127) at net.lukemurphey.nsia.scan.ScriptDefinition.<init>(ScriptDefinition.java:110) at net.lukemurphey.nsia.scan.ScriptDefinition.<init>(ScriptDefinition.java:102) at net.lukemurphey.nsia.scan.ScriptDefinition.parse(ScriptDefinition.java:86) at net.lukemurphey.nsia.scan.DefinitionSet.loadFromXml(DefinitionSet.java:457) at net.lukemurphey.nsia.scan.DefinitionSet.loadFromString(DefinitionSet.java:738) at net.lukemurphey.nsia.scan.DefinitionArchive.updateDefinitions(DefinitionArchive.java:1019) at net.lukemurphey.nsia.web.views.DefinitionsImportView.process(DefinitionsImportView.java:94) at net.lukemurphey.nsia.web.View.process(View.java:92) at net.lukemurphey.nsia.web.View.process(View.java:59) at net.lukemurphey.nsia.web.WebConsoleServlet.doRequest(WebConsoleServlet.java:83) at net.lukemurphey.nsia.web.WebConsoleServlet.doPost(WebConsoleServlet.java:130) at javax.servlet.http.HttpServlet.service(HttpServlet.java:154) at javax.servlet.http.HttpServlet.service(HttpServlet.java:92) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:428) at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:473) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568) at org.mortbay.http.HttpContext.handle(HttpContext.java:1530) at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:633) at org.mortbay.http.HttpContext.handle(HttpContext.java:1482) at org.mortbay.http.HttpServer.service(HttpServer.java:909) at org.mortbay.http.HttpConnection.service(HttpConnection.java:820) at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:986) at org.mortbay.http.HttpConnection.handle(HttpConnection.java:837) at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:245) at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357) at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)

Caused by:java.lang.ClassNotFoundException: sun.org.mozilla.javascript.internal.Context
java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at net.lukemurphey.nsia.scan.ScriptDefinition.getScriptEngine(ScriptDefinition.java:162) at net.lukemurphey.nsia.scan.ScriptDefinition.<init>(ScriptDefinition.java:127) at net.lukemurphey.nsia.scan.ScriptDefinition.<init>(ScriptDefinition.java:110) at net.lukemurphey.nsia.scan.ScriptDefinition.<init>(ScriptDefinition.java:102) at net.lukemurphey.nsia.scan.ScriptDefinition.parse(ScriptDefinition.java:86) at net.lukemurphey.nsia.scan.DefinitionSet.loadFromXml(DefinitionSet.java:457) at net.lukemurphey.nsia.scan.DefinitionSet.loadFromString(DefinitionSet.java:738) at net.lukemurphey.nsia.scan.DefinitionArchive.updateDefinitions(DefinitionArchive.java:1019) at net.lukemurphey.nsia.web.views.DefinitionsImportView.process(DefinitionsImportView.java:94) at net.lukemurphey.nsia.web.View.process(View.java:92) at net.lukemurphey.nsia.web.View.process(View.java:59) at net.lukemurphey.nsia.web.WebConsoleServlet.doRequest(WebConsoleServlet.java:83) at net.lukemurphey.nsia.web.WebConsoleServlet.doPost(WebConsoleServlet.java:130) at javax.servlet.http.HttpServlet.service(HttpServlet.java:154) at javax.servlet.http.HttpServlet.service(HttpServlet.java:92) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:428) at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:473) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568) at org.mortbay.http.HttpContext.handle(HttpContext.java:1530) at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:633) at org.mortbay.http.HttpContext.handle(HttpContext.java:1482) at org.mortbay.http.HttpServer.service(HttpServer.java:909) at org.mortbay.http.HttpConnection.service(HttpConnection.java:820) at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:986) at org.mortbay.http.HttpConnection.handle(HttpConnection.java:837) at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:245) at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357) at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)

History

#1 Updated by Luke Murphey over 7 years ago

  • Description updated (diff)

#2 Updated by Luke Murphey over 7 years ago

Error is here, when attempting to control the context of the script:

        // 2 -- Set the context such that the script class loader will be used.
        Context context = Context.enter();
        context.setApplicationClassLoader(new ScriptClassLoader());

#4 Updated by Luke Murphey over 7 years ago

It looks like I need to use a thread with a classloader. I might be able to set the class loader on the InvokeThread:. Below is the call structure:

  • baseline
  • evaluate
    • performAnalysis
      • InvokerThread

#5 Updated by Luke Murphey over 7 years ago

Changes:
  • Remove import of sun.org.mozilla.javascript.internal.Context
  • Remove use of Context in getScriptEngine()
  • getScriptEngine() eval likely needs to use a thread
  • set the classloader for the InvokerThread class
  • change baseline() to use a thread with the class loader

#6 Updated by Luke Murphey over 7 years ago

Questions:

#8 Updated by Luke Murphey over 7 years ago

import jdk.nashorn.api.scripting.*;
import javax.script.*;

NashornScriptEngineFactory factory = new NashornScriptEngineFactory();

ClassLoader classLoader = this.getClass().getClassLoader();
ScriptEngine engine = factory.getScriptEngine(new String[] { "--global-per-engine" }, classLoader);
public class ScriptClassLoader extends ClassLoader {
    public Class<?> loadClass(String className) throws ClassNotFoundException {
        throw new ClassNotFoundException("Class " + className + " not found");
    }
}

ScriptClassLoader classLoader = new ScriptClassLoader();

Also available in: Atom PDF