Regression: wrapException throws unexpected exceptions depending on
previously-run code
---------------------------------------------------------------------------------------
Key: JRUBY-5689
URL: http://jira.codehaus.org/browse/JRUBY-5689
Project: JRuby
Issue Type: Bug
Components: Embedding
Affects Versions: JRuby 1.6
Reporter: Trejkaz
Take the following test:
{code:java}
@Test
public void test3() throws Exception
{
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByExtension("rb");
ScriptContext context = new SimpleScriptContext();
StringWriter writer = new StringWriter();
context.setWriter(writer);
context.setErrorWriter(writer);
try
{
context.setAttribute("runnable", new Runnable()
{
@Override
public void run()
{
throw new RuntimeException("Got an error");
}
}, ScriptContext.ENGINE_SCOPE);
engine.eval("$runnable.run()", context);
fail("Expected ScriptException");
}
catch (ScriptException e)
{
RaiseException cause = (RaiseException) e.getCause();
// Now we expect the real exception in here.
RuntimeException realCause = (RuntimeException) cause.getCause();
assertEquals("Wrong runtime exception", "Got an error",
realCause.getMessage());
}
}
{code}
This test will pass.
But if you run this before it:
{code:java}
@Test
public void test2() throws Exception
{
String orig = "\u30C6\u30B9\u30C8";
ScriptingContainer container = new ScriptingContainer();
StringWriter writer = new StringWriter();
container.setWriter(writer);
Object returnedResult = container.runScriptlet("str = \"" + orig + "\"
; puts str ; str");
//noinspection ErrorNotRethrown
try
{
assertEquals("Wrong result returned", orig, returnedResult);
assertEquals("Wrong result printed", orig,
writer.toString().trim());
fail("Expected AssertionError. This is a good thing - update the
test.");
}
catch (AssertionError e)
{
// Currently expected due to the bug.
}
}
{code}
Now the test will fail:
{noformat}
java.lang.NullPointerException
at TestJRuby.test3(TestJRuby.java:160)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
{noformat}
Somehow $utilities is not accessible anymore, after another test is run.
Now run this test at the front:
{code:java}
@Test
public void test1() throws Exception
{
String orig = "\u30C6\u30B9\u30C8";
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByExtension("rb");
ScriptContext context = new SimpleScriptContext();
StringWriter writer = new StringWriter();
context.setWriter(writer);
Object returnedResult = engine.eval("str = \"" + orig + "\" ; puts str
; str", context);
//noinspection ErrorNotRethrown
try
{
assertEquals("Wrong result returned", orig, returnedResult);
assertEquals("Wrong result printed", orig,
writer.toString().trim());
fail("Expected AssertionError. This is a good thing - update the
test.");
}
catch (AssertionError e)
{
// Currently expected due to the bug.
}
}
{code}
Suddenly it fails for a different reason entirely:
{noformat}
java.lang.NullPointerException
at
org.jruby.embed.jsr223.JRubyEngine.wrapException(JRubyEngine.java:110)
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:93)
at TestJRuby.test3(TestJRuby.java:151)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
{noformat}
Now remove test2 again, and mysteriously you get the first exception again:
{noformat}
java.lang.NullPointerException
at TestJRuby.test3(TestJRuby.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
{noformat}
This is quite perplexing as one test is interacting with another test which
isn't even sharing any objects with the first (or at least, it is led to
believe this.)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email