scripting
  1. scripting
  2. SCRIPTING-36

Instantiating JRubyScriptEngineFactory fails with "No such file or directory (IOError)"

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: milestone 1
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: Linux
      Platform: PC

    • Issuezilla Id:
      36

      Description

      ScriptEngineFactory scriptEngineFactory = new JRubyScriptEngineFactory();
      ScriptEngine scriptEngine = scriptEngineFactory.getScriptEngine();

      scriptEngine.eval("puts 'Hello World'");

      The call to new JRubyScriptEngineFactory() generates this exception:

      No such file or directory
      :1: No such file or directory (IOError)
      ...internal jruby stack elided...

      There is no stack trace provided. I tried to step through in the debugger. It
      blows up somewhere in this method:
      private void init(String loadPath) {
      runtime = Ruby.newInstance();
      IAccessor d = new ValueAccessor(runtime.newString("<script>"));
      runtime.getGlobalVariables().define("$PROGRAM_NAME", d);
      runtime.getGlobalVariables().define("$0", d);
      if (loadPath == null)

      { loadPath = System.getProperty("java.class.path"); }

      List list = Arrays.asList(loadPath.split(File.pathSeparator));
      runtime.getLoadService().init(list);
      runtime.getLoadService().require("java");
      }

      I get to this line in the debugger
      IAccessor d = new ValueAccessor(runtime.newString("<script>"));

      And then try stepping through. Everything appears fine and then when the new
      ValueAccessor() call tries to return it blows up. There may be a slight
      mismatch between the source code I am using and the JAR file.

      It's worth mentioning that when i run that example directly as a main class it
      works fine, but the actual example that is failing in our application is using a
      chained classloader. I don't see though how/why this would yield that specific
      error.

      Is there anything I can do to get more verbose diagnostics here? For starters,
      it would be nice to no which file it was looking for that it couldn't find.

        Activity

        Hide
        sirianni added a comment -

        After some more digging it looks like the problem was that there was a JAR file
        foo.jar in "java.class.path" (i.e. java -cp ....:/path/to/foo.jar:... ) that was
        not present in the file system.

        if(null == current) {
        try {
        if(entry.startsWith("jar:"))

        { current = new JarFile(entry.substring(4)); }

        else if (entry.endsWith(".jar"))

        { current = new JarFile(entry); }

        else

        { current = new JarFile(entry.substring(5,entry.indexOf("!/"))); }

        jarFiles.put(entry,current);
        } catch (FileNotFoundException ignored)

        { >>> }

        catch (IOException e)

        { throw runtime.newIOErrorFromException(e); }

        }

        This line above was getting a java.util.zip.ZipException: No such file or directory

        Two things...
        1. It seems bad to be iterating over java.class.path to find resources since
        there are other ways of defining the application's classpath (MANIFESTS, war
        files, etc.)
        2. Your "FileNotFoundException ignored" is not being caught because ZipException
        is not a subclass of FileNotFoundException

        Show
        sirianni added a comment - After some more digging it looks like the problem was that there was a JAR file foo.jar in "java.class.path" (i.e. java -cp ....:/path/to/foo.jar:... ) that was not present in the file system. if(null == current) { try { if(entry.startsWith("jar:")) { current = new JarFile(entry.substring(4)); } else if (entry.endsWith(".jar")) { current = new JarFile(entry); } else { current = new JarFile(entry.substring(5,entry.indexOf("!/"))); } jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { >>> } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } This line above was getting a java.util.zip.ZipException: No such file or directory Two things... 1. It seems bad to be iterating over java.class.path to find resources since there are other ways of defining the application's classpath (MANIFESTS, war files, etc.) 2. Your "FileNotFoundException ignored" is not being caught because ZipException is not a subclass of FileNotFoundException
        Hide
        sirianni added a comment -

        You can close this. The bug is in JRuby itself.

        I've filed bug http://jira.codehaus.org/browse/JRUBY-2782 for this issue.

        Show
        sirianni added a comment - You can close this. The bug is in JRuby itself. I've filed bug http://jira.codehaus.org/browse/JRUBY-2782 for this issue.

          People

          • Assignee:
            yokolet
            Reporter:
            sirianni
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: