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

$! not always being saved/restored in JRuby runtime when Ruby exceptions are handled #1601

Closed
subbuss opened this issue Apr 1, 2014 · 5 comments

Comments

@subbuss
Copy link
Contributor

subbuss commented Apr 1, 2014

Several classes in the JRuby runtime are catching Ruby exceptions. Those should save the old value of $! and restore them after the exception is handled. A quick grep revealed at the following files that need investigation and possible fixup. I've fixed up RubyFileTest.java in commit d10eade

[subbu@earth ir] grep -l 'catch (RaiseExcep' ../*
../Main.java
../RubyBasicObject.java
../RubyComparable.java
../RubyConverter.java
../RubyEnumerable.java
../RubyEnumerator.java
../RubyFile.java
../RubyFileTest.java
../RubyIO.java
../Ruby.java
../RubyKernel.java
../RubyNumeric.java
../RubyRange.java
../RubyRegexp.java

@headius
Copy link
Member

headius commented Apr 1, 2014

I think with very few exceptions, if we're catching a RaiseException we should probably be clearing $!. However...I also suspect most of the time if w're catching RaiseException in Java code that $! will not be set, since we generally set/clear only for rescue/ensure.

@enebo
Copy link
Member

enebo commented May 7, 2014

Reproduced an example using <=>:

begin
  0 <=> Time.now
rescue
  puts "AAAA"
end

begin
  raise
rescue
  puts "C: #{$!}"
end

@subbuss
Copy link
Contributor Author

subbuss commented Feb 14, 2015

Reopening so we can audit code and confirm everything is good.

kares pushed a commit to kares/jruby that referenced this issue Aug 17, 2015
kares added a commit to kares/jruby that referenced this issue Aug 17, 2015
kares added a commit that referenced this issue Aug 18, 2015
* jruby-1_7:
  some more comparable asserts including for the Java compareTo part
  native RubySymbol#compareTo since we expect to always be able to sort
  should not-rewrite jump exceptions twice as well (not just raise ones)
  delete un-used imports
  [ji] do not rewrite stack-trace twice for Ruby (raise) exceptions
  base compareTo should not silence all Ruby raised exceptions (fixes #2232)
  re-arrange rescue spec (we're about to spec some more behavior)
  only test nil return from Object cmp on 1.9 (on 1.8.7 its expected to raise)
  more of correct $! restore + use get/setErrorInfo for better predictability
  another incorrect $! with numeric coercion on <=> + cleanup getRuntime()
  Fix some consumers for #1601.  Don't leak out  if we are swallowing the raised exception

Conflicts:
	core/src/main/java/org/jruby/Main.java
	core/src/main/java/org/jruby/RubyBasicObject.java
	core/src/main/java/org/jruby/RubyClass.java
	core/src/main/java/org/jruby/RubyComparable.java
	core/src/main/java/org/jruby/RubyNumeric.java
	core/src/main/java/org/jruby/RubySymbol.java
	core/src/main/java/org/jruby/RubyTime.java
	core/src/main/java/org/jruby/javasupport/JavaCallable.java
@kares
Copy link
Member

kares commented Jun 10, 2017

has been open for 2+y ... just did a quick audit and all seems well. maybe the time has come to close? 😉

@headius
Copy link
Member

headius commented Jun 13, 2017

@kares 👍

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

No branches or pull requests

4 participants