title: Can't figure out why ScriptEngine engine is null in code
body: <p>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.).</p>
  <p>I am also using jdk1.7.0_80</p>
  <pre><code>lang-java
  package scripting;
  
  import java.io.File; 
  import java.io.FileReader; 
  import java.io.IOException;
  import javax.script.Invocable; 
  import javax.script.ScriptEngine;
  import javax.script.ScriptEngineManager;
  import client.MapleClient; 
  import tools.FileoutputUtil;
  
  public abstract class AbstractScriptManager {
  
      private static final ScriptEngineManager sem = new ScriptEngineManager(null);
  
      protected Invocable getInvocable(String path, MapleClient c) {
          return getInvocable(path, c, false);
      }
  
      protected Invocable getInvocable(String path, MapleClient c, boolean npc) {
          FileReader fr = null;
          try {
              path = &quot;scripts/&quot; + path;
              ScriptEngine engine = null;
  
              if (c != null) {
                  engine = c.getScriptEngine(path);
              }
              if (engine == null) {
                  File scriptFile = new File(path);
                  if (!scriptFile.exists()) {
                      return null;
                  }
                  engine = sem.getEngineByName(&quot;JavaScript&quot;);
                  if (c != null) {
                      c.setScriptEngine(path, engine);
                  }
                  fr = new FileReader(scriptFile);
                  engine.eval(fr);
              } else if (c != null &amp;&amp; npc) {
                  c.getPlayer().dropMessage(-1, &quot;You already are talking to this NPC. Use @ea if this is 
                  not intended.&quot;);
              }
              return (Invocable) engine;
          } catch (Exception e) {
              System.err.println(&quot;Error executing script. Path: &quot; + path + &quot;\nException &quot; + e);
              FileoutputUtil.log(FileoutputUtil.ScriptEx_Log, &quot;Error executing script. Path: &quot; + path + 
              &quot;\nException &quot; + e);
              return null;
          } finally {
              try {
                  if (fr != null) {
                      fr.close();
                  }
              } catch (IOException ignore) {
  
              }
          }
      } 
  }
  </code></pre>
  <p><strong>This is the bat error I receive:</strong></p>
  <blockquote>
  <p>Error executing script. Path: scripts/event/someEvent.js Exception
  java.lang.NullPointerException: Cannot invoke
  &quot;javax.script.ScriptEngine.eval(java.io.Reader)&quot; because &quot;engine&quot; is null</p>
  </blockquote>
  <p>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).</p>