JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-6724

NO_FILE_CLASS Profile does disables File but not FileStats that depends on File

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.7.0.pre1
    • Fix Version/s: JRuby 1.7.0.pre2
    • Component/s: Core Classes/Modules
    • Labels:
    • Environment:
      linux BackTrack 5 R1 x86, JVM oracle 1.7.0_03, building a project including jruby-1.7.0.preview1 on Apache Maven 3.0.4 as compile-scope dependency
    • Number of attachments :
      1

      Description

      instantiating a org.jruby.embed.jsr223.JRubyEngine using the constructor "JRubyEngine(ScriptingContainer container, JRubyEngineFactory factory)",
      when a org.jruby.embed.ScriptingContainer configured with a Profile.NO_FILE_CLASS causes the org.jruby.Ruby initCore() method to skip the creation of RubyFile class at line 1380, but it does not prevent the creation of RubyFileStat class at line 1383, resulting in a NPE on statement "..= runtime.getFile().defineClassUnder( .." in org.jruby.RubyFileStat, line 75.

      Don't know enough the library to say it for sure, but the problem may be the condition "public boolean allowClass(String name)

      { return !name.equals("File"); }

      " in org.jruby.Profile line 50.

      1. RubyTest.java
        3 kB
        Tsukihara Caligin

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        Good find!

        Show
        Charles Oliver Nutter added a comment - Good find!
        Hide
        Charles Oliver Nutter added a comment -

        Ok, I committed a fix, but would appreciate if you could come up with a test case to add to our set of embedding tests.

        commit c580ea8bcb3d7dd84227b4f0bee7ecc9575f826a
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Thu Jun 28 22:06:00 2012 -0500
        
            Fix JRUBY-6724
            
            NO_FILE_CLASS Profile does disables File but not FileStats that depends on File
            
            Fix NO_FILE_CLASS profile to also disable FileStat.
        
        Show
        Charles Oliver Nutter added a comment - Ok, I committed a fix, but would appreciate if you could come up with a test case to add to our set of embedding tests. commit c580ea8bcb3d7dd84227b4f0bee7ecc9575f826a Author: Charles Oliver Nutter <headius@headius.com> Date: Thu Jun 28 22:06:00 2012 -0500 Fix JRUBY-6724 NO_FILE_CLASS Profile does disables File but not FileStats that depends on File Fix NO_FILE_CLASS profile to also disable FileStat.
        Hide
        Tsukihara Caligin added a comment -

        Fix is incorrect (check for FiseStat instead of File::Stat).
        Also, it does not resolve the issue: disabling File without disabling Gem still results in an error.
        Attaching a test case class.
        (To be honest I replied you by mail last week, but I somehow can't find it in the sent folder O_o)

        Show
        Tsukihara Caligin added a comment - Fix is incorrect (check for FiseStat instead of File::Stat). Also, it does not resolve the issue: disabling File without disabling Gem still results in an error. Attaching a test case class. (To be honest I replied you by mail last week, but I somehow can't find it in the sent folder O_o)
        Hide
        Charles Oliver Nutter added a comment -

        Ok, I corrected the typo, and it does indeed appear to load now without File or File::Stat (confirmed by calling ruby.getFile() and getFileStat()). I also modified your test case to remove the expected exceptions, and it passes; the runtime is able to boot properly. Is this what you're looking for?

        Note that JRuby 1.7 will start in 1.9 mode by default, and will always try to load RubyGems. You must add the command line --disable-gems to turn that off (and perhaps this is something that should be in the Profile too?).

        Here's the patch...can you confirm that it does what you want it to?

        diff --git a/src/org/jruby/Profile.java b/src/org/jruby/Profile.java
        index e8aa6b3..65b8740 100644
        --- a/src/org/jruby/Profile.java
        +++ b/src/org/jruby/Profile.java
        @@ -47,7 +47,7 @@ public interface Profile {
                 };
             Profile NO_FILE_CLASS = new Profile() {
                     public boolean allowBuiltin(String name) { return true; }
        -            public boolean allowClass(String name) { return !(name.equals("File") || name.equals("FileStat")); }
        +            public boolean allowClass(String name) { return !(name.equals("File") || name.equals("File::Stat")); }
                     public boolean allowModule(String name) { return true; }
                     public boolean allowLoad(String name) { return true; }
                     public boolean allowRequire(String name) { return true; }
        
        Show
        Charles Oliver Nutter added a comment - Ok, I corrected the typo, and it does indeed appear to load now without File or File::Stat (confirmed by calling ruby.getFile() and getFileStat()). I also modified your test case to remove the expected exceptions, and it passes; the runtime is able to boot properly. Is this what you're looking for? Note that JRuby 1.7 will start in 1.9 mode by default, and will always try to load RubyGems. You must add the command line --disable-gems to turn that off (and perhaps this is something that should be in the Profile too?). Here's the patch...can you confirm that it does what you want it to? diff --git a/src/org/jruby/Profile.java b/src/org/jruby/Profile.java index e8aa6b3..65b8740 100644 --- a/src/org/jruby/Profile.java +++ b/src/org/jruby/Profile.java @@ -47,7 +47,7 @@ public interface Profile { }; Profile NO_FILE_CLASS = new Profile() { public boolean allowBuiltin(String name) { return true; } - public boolean allowClass(String name) { return !(name.equals("File") || name.equals("FileStat")); } + public boolean allowClass(String name) { return !(name.equals("File") || name.equals("File::Stat")); } public boolean allowModule(String name) { return true; } public boolean allowLoad(String name) { return true; } public boolean allowRequire(String name) { return true; }
        Hide
        Tsukihara Caligin added a comment -

        The patch is surely correct.
        However using this profile will result in an error during the loading of RubyGems if it's not disables, perhaps this should be documented.
        My use case is involves JSR-223, so I don't start the jRuby cli but instantiate a ScriptEngine, however I found that RubyGems could be programmatically disabled from the engine's runtime bootstrap with

        final RubyInstanceConfig config = new RubyInstanceConfig();
        config.setDisableGems(true);
        

        I'm pretty new to jRuby so I hope I didn't say some heresy...
        Thanks for the support.

        Show
        Tsukihara Caligin added a comment - The patch is surely correct. However using this profile will result in an error during the loading of RubyGems if it's not disables, perhaps this should be documented. My use case is involves JSR-223, so I don't start the jRuby cli but instantiate a ScriptEngine, however I found that RubyGems could be programmatically disabled from the engine's runtime bootstrap with final RubyInstanceConfig config = new RubyInstanceConfig(); config.setDisableGems(true); I'm pretty new to jRuby so I hope I didn't say some heresy... Thanks for the support.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Tsukihara Caligin
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: