Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting "BUG: $! and exception are not matching up" in RSpec in 9K #2514

Closed
iconara opened this issue Jan 24, 2015 · 3 comments
Closed

Getting "BUG: $! and exception are not matching up" in RSpec in 9K #2514

iconara opened this issue Jan 24, 2015 · 3 comments

Comments

@iconara
Copy link
Contributor

iconara commented Jan 24, 2015

I'm getting this message when running tests in 9K, but not in 1.7:

BUG: $! and exception are not matching up.
$!: org.jruby.exceptions.RaiseException: (RuntimeError) bork
t : org.jruby.exceptions.RaiseException: (RuntimeError) bork

I've narrowed it down and can trigger the message with the following code:

begin
  executor = java.util.concurrent.Executors.new_single_thread_executor
  future = executor.submit { raise 'bork' }
  future.get
rescue => e
  # e is an ExecutionException, which wraps a org.jruby.exceptions.RaiseException,
  # which wraps the actual Ruby exception
  raise e.cause
end

Running that code with rspec code.rb in JRuby 9K prints the message 12 times, running it with ruby code.rb in JRuby 9K, or rspec code.rb in JRuby 1.7 does not. There's nothing in the code that actually refers to RSpec so it must be caused by something that RSpec does that works differently in 1.7 and 9K, and at first I thought it was a message from RSpec, but I found the JRuby code that prints the message:

if ((t instanceof RaiseException) && context.runtime.getGlobalVariables().get("$!") != IRRuntimeHelpers.unwrapRubyException(t)) {
System.err.println("BUG: $! and exception are not matching up.");
System.err.println("$!: " + context.runtime.getGlobalVariables().get("$!"));
System.err.println("t : " + t);
}

should this really print directly to stderr? Shouldn't it go to the logger? Also, from the message it prints it looks like the exceptions are the same. It's also weird that the message gets printed 12 times, even though the exception is only raised once.

@subbuss subbuss added this to the 9.0.0.0.pre2 milestone Jan 27, 2015
@subbuss subbuss added the ir label Jan 27, 2015
@subbuss
Copy link
Contributor

subbuss commented Jan 27, 2015

Interesting .. some code in our runtime is cloning the exception object. @headius @enebo

@subbuss
Copy link
Contributor

subbuss commented Feb 15, 2015

It is not rspec related. I think the exception obj is getting cloned somewhere on the way between the java->ruby bridge and the VM. The reason it is printing 12 times is because the exception is unwinding the call stack and in each scope, the interpreter is checking whether they match up ( and of course, they won't ).

@subbuss
Copy link
Contributor

subbuss commented Feb 15, 2015

This is a red herring ...

BUG: $! and exception are not matching up.
$!: org.jruby.exceptions.RaiseException: (RuntimeError) bork
$!.class: org.jruby.java.proxies.ConcreteJavaProxy
Unwrapped RaiseException : bork
Unwrapped RaiseException .class: org.jruby.RubyException

They don't match up because of the proxy wrapping for java exceptions which is why you are catching and rethrowing in that rescue handler. That check was meant to detect bugs in the runtime and VM .. but, so far we haven't had any other reports besides yours (which turns out to be all fine). So, I am going to get rid of that test and be done with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants