Skip to content
Advertisement

Can’t figure out why ScriptEngine engine is null in code

This is some of the code I’m running for a MapleStory server. Whenever a script for an event like talking to an NPC is supposed to occur, this script will be run to create a scripting path for whatever script is being called up (NPC, portal, event etc.).

I am also using jdk1.7.0_80

JavaScript

This is the bat error I receive:

Error executing script. Path: scripts/event/someEvent.js Exception java.lang.NullPointerException: Cannot invoke “javax.script.ScriptEngine.eval(java.io.Reader)” because “engine” is null

These errors are thrown whenever I try to interact with something that utilizes this method (i.e. clicking NPC or on server start-up when some scripts are run).

Advertisement

Answer

The NullPointerException occurs because the Java Runtime you’re using doesn’t have a “JavaScript” Script Engine installed, causing sem.getEngineByName("JavaScript") to return null.

That was verified (see comment) by running the following code:

JavaScript

When I run this on various Java implementations on Windows 10, I get the following results:

JavaScript

As you can see, the OpenJDK version of Java 7 doesn’t have a JavaScript engine, because the Mozilla Rhino library isn’t open-source. You need the Oracle version of Java 7 to get the JavaScript engine.

You can also see that JavaScript was removed in Java 15, as documented in the JDK 15 Release Notes:

The Nashorn JavaScript script engine, its APIs, and the jjs tool have been removed. The engine, the APIs, and the tool were deprecated for removal in Java 11 with the express intent to remove them in a future release. See JDK-8236933

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement