-
-
Save marshalium/64e9ebb4bb4ac107eee1f5a629feee18 to your computer and use it in GitHub Desktop.
Reproduce JRuby issue #4699
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.function.Supplier; | |
public class ExceptionHelper { | |
private final Throwable error; | |
public ExceptionHelper(Supplier<Void> errorRaisingSupplier) { | |
this.error = errorFromSupplier(errorRaisingSupplier); | |
} | |
private static Throwable errorFromSupplier(Supplier<Void> errorRaisingSupplier) { | |
try { | |
errorRaisingSupplier.get(); | |
} catch (Throwable t) { | |
return t; | |
} | |
throw new RuntimeException("Supplier did not raise an error"); | |
} | |
public void throwCachedError() throws RuntimeException { | |
throw new RuntimeException("Wrapper around cached error", this.error); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env jruby | |
NUM_THREADS = 5 | |
puts RUBY_DESCRIPTION | |
class CustomError < StandardError; end | |
class ErrorRaiser | |
def initialize | |
@java_exception_helper = Java::ExceptionHelper.new { raise CustomError } | |
end | |
def get | |
begin | |
begin | |
@java_exception_helper.throwCachedError(); | |
rescue Java::JavaLang::RuntimeException => e | |
raise e.cause | |
end | |
rescue CustomError | |
nil | |
end | |
end | |
end | |
error_raiser = ErrorRaiser.new | |
puts "Starting #{NUM_THREADS} threads" | |
threads = NUM_THREADS.times.map do | |
Thread.new do | |
begin | |
10_000.times do | |
error_raiser.get | |
end | |
puts "#{Thread.current} finished successfully!\n" | |
rescue => e | |
puts "#{Thread.current} failed" | |
puts "#{e.class}: #{e}\n\t#{e.backtrace.join("\n\t")}\n" | |
end | |
end | |
end | |
puts "Waiting for all threads to finish" | |
threads.map(&:join) | |
puts "DONE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Building and running this results in this: