Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a test reproducing backtrace issue #3177
Browse files Browse the repository at this point in the history
kares committed Aug 8, 2015
1 parent 257e730 commit f567247
Showing 2 changed files with 50 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/org/jruby/javasupport/test/ThrowingRunnable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jruby.javasupport.test;

/**
* https://github.com/jruby/jruby/issues/3177
*
* @see test_backtraces.rb
*/
public class ThrowingRunnable {

final Runnable runnable;

public ThrowingRunnable(Runnable run) {
runnable = run;
}

public void doRun(boolean fail) throws Exception {
if (fail) throw new Exception();
runnable.run();
}

}
29 changes: 29 additions & 0 deletions test/test_backtraces.rb
Original file line number Diff line number Diff line change
@@ -258,6 +258,35 @@ def test_exception_from_thread_with_abort_on_exception_true
$stderr = STDERR
end

def test_throwing_runnable_backtrace # GH-3177
fixnum_times_ = 'org.jruby.RubyFixnum.times(org/jruby/RubyFixnum.java:'
backtrace = nil

i = 0
throwing = org.jruby.javasupport.test.ThrowingRunnable.new do
1.times {
begin
throwing.doRun( (i += 1) > 0 )
rescue java.lang.Exception
assert e = $!.backtrace.find { |e| e.index('org.jruby.RubyFixnum.times') }
assert_equal fixnum_times_, e[ 0...fixnum_times_.size ]
backtrace = $!.backtrace.dup
raise
end
}
end

begin
throwing.doRun(false)
rescue java.lang.Exception
# puts $!.backtrace
# second rewriting of the same exception :
assert e = $!.backtrace.find { |e| e.index('org.jruby.RubyFixnum.times') }
assert_equal fixnum_times_, e[ 0...fixnum_times_.size ]
assert_equal backtrace, $!.backtrace # expect the same back-trace
end
end

private

# Convenience method to obtain the exception,

0 comments on commit f567247

Please sign in to comment.