Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6.1, JRuby 1.6.5
-
Fix Version/s: JRuby 1.6.6, JRuby 1.7.0.pre1
-
Component/s: Embedding
-
Labels:None
-
Number of attachments :
Description
The following test:
@Test
public void testJRubyExitBehaviour() throws Exception
{
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByExtension("rb");
try
{
engine.eval("exit 3");
fail("Expected ScriptException");
}
catch (ScriptException e)
{
// Expected
}
}
The test itself does actually pass, but what's bad here is that it logs the following to stderr:
SystemExit: exit
exit at org/jruby/RubyKernel.java:867
exit at org/jruby/RubyKernel.java:836
(root) at <script>:1
org.jruby.embed.EvalFailedException: (SystemExit) exit
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:127)
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:90)
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:153)
at com.nuix.script.TestScriptUtils.testJRubyExitBehaviour(TestScriptUtils.java:25)
...26 lines elided...
Caused by: org.jruby.exceptions.RaiseException: (SystemExit) exit
This makes it difficult if you're trying to write a command-line application which wants to display a nice usage message to the user and then exit - they can't read the usage message because they get a page full of errors after it.
The main jruby runtime itself doesn't appear to do this with the same kind of script, so I figure the error is limited to when you're embedding.
I think it's reasonable to assume that "exit" within an embedded script will simply bubble out the exit status as the script's result. Yoko: I'm interested in your thoughts. Meanwhile, I'm fixing it this way.