Created
December 29, 2014 18:10
-
-
Save headius/e87a4723d643cfd38769 to your computer and use it in GitHub Desktop.
Attempt at fixing JRUBY-7129
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
diff --git a/core/src/main/java/org/jruby/RubyThread.java b/core/src/main/java/org/jruby/RubyThread.java | |
index cf325de..cbc0c82 100644 | |
--- a/core/src/main/java/org/jruby/RubyThread.java | |
+++ b/core/src/main/java/org/jruby/RubyThread.java | |
@@ -55,6 +55,7 @@ import org.jruby.internal.runtime.NativeThread; | |
import org.jruby.internal.runtime.RubyRunnable; | |
import org.jruby.internal.runtime.ThreadLike; | |
import org.jruby.internal.runtime.ThreadService; | |
+import org.jruby.javasupport.JavaUtil; | |
import org.jruby.runtime.Block; | |
import org.jruby.runtime.ObjectAllocator; | |
import org.jruby.runtime.ThreadContext; | |
@@ -119,7 +120,7 @@ public class RubyThread extends RubyObject implements ExecutionContext { | |
* it here to continue propagating it while handling thread shutdown | |
* logic and abort_on_exception. | |
*/ | |
- private RaiseException exitingException; | |
+ private Throwable exitingException; | |
/** The ThreadGroup to which this thread belongs */ | |
private RubyThreadGroup threadGroup; | |
@@ -711,7 +712,7 @@ public class RubyThread extends RubyObject implements ExecutionContext { | |
if (exitingException != null) { | |
// Set $! in the current thread before exiting | |
- getRuntime().getGlobalVariables().set("$!", (IRubyObject)exitingException.getException()); | |
+ getRuntime().getGlobalVariables().set("$!", (IRubyObject)exitingException); | |
throw exitingException; | |
} | |
@@ -927,7 +928,6 @@ public class RubyThread extends RubyObject implements ExecutionContext { | |
* Ruby threads like Timeout's thread. | |
* | |
* @param args Same args as for Thread#raise | |
- * @param block Same as for Thread#raise | |
*/ | |
public void internalRaise(IRubyObject[] args) { | |
Ruby runtime = getRuntime(); | |
@@ -1175,53 +1175,49 @@ public class RubyThread extends RubyObject implements ExecutionContext { | |
return threadImpl.isCurrent(); | |
} | |
- public void exceptionRaised(RaiseException exception) { | |
+ public void exceptionRaised(Throwable exception) { | |
assert isCurrent(); | |
- RubyException rubyException = exception.getException(); | |
- Ruby runtime = rubyException.getRuntime(); | |
- if (runtime.getSystemExit().isInstance(rubyException)) { | |
- runtime.getThreadService().getMainThread().raise(new IRubyObject[] {rubyException}, Block.NULL_BLOCK); | |
- } else if (abortOnException(runtime)) { | |
- RubyException systemExit; | |
- | |
- if (!runtime.is1_9()) { | |
- runtime.printError(rubyException); | |
- String message = rubyException.message.convertToString().toString(); | |
- systemExit = RubySystemExit.newInstance(runtime, 1, message); | |
- systemExit.set_backtrace(rubyException.backtrace()); | |
- } else { | |
- systemExit = rubyException; | |
- } | |
- | |
- runtime.getThreadService().getMainThread().raise(new IRubyObject[] {systemExit}, Block.NULL_BLOCK); | |
- return; | |
- } else if (runtime.getDebug().isTrue()) { | |
- runtime.printError(exception.getException()); | |
- } | |
- exitingException = exception; | |
- } | |
+ Ruby runtime = getRuntime(); | |
- /** | |
- * For handling all non-Ruby exceptions bubbling out of threads | |
- * @param exception | |
- */ | |
- @SuppressWarnings("deprecation") | |
- public void exceptionRaised(Throwable exception) { | |
if (exception instanceof RaiseException) { | |
- exceptionRaised((RaiseException)exception); | |
- return; | |
- } | |
- | |
- assert isCurrent(); | |
+ RubyException rubyException = ((RaiseException) exception).getException(); | |
+ if (runtime.getSystemExit().isInstance(rubyException)) { | |
+ runtime.getThreadService().getMainThread().raise(new IRubyObject[]{rubyException}, Block.NULL_BLOCK); | |
+ } else if (abortOnException(runtime)) { | |
+ RubyException systemExit; | |
+ | |
+ if (!runtime.is1_9()) { | |
+ runtime.printError(rubyException); | |
+ String message = rubyException.message.convertToString().toString(); | |
+ systemExit = RubySystemExit.newInstance(runtime, 1, message); | |
+ systemExit.set_backtrace(rubyException.backtrace()); | |
+ } else { | |
+ systemExit = rubyException; | |
+ } | |
- Ruby runtime = getRuntime(); | |
- if (abortOnException(runtime) && exception instanceof Error) { | |
- // re-propagate on main thread | |
- runtime.getThreadService().getMainThread().getNativeThread().stop(exception); | |
+ runtime.getThreadService().getMainThread().raise(new IRubyObject[]{systemExit}, Block.NULL_BLOCK); | |
+ return; | |
+ } else if (runtime.getDebug().isTrue()) { | |
+ runtime.printError(rubyException); | |
+ } | |
+ exitingException = rubyException; | |
+ } else if (exception instanceof Error) { | |
+ if (abortOnException(runtime)) { | |
+ // re-propagate on main thread | |
+ runtime.getThreadService().getMainThread().getNativeThread().stop(exception); | |
+ exitingException = JavaUtil.convertJavaToUsableRubyObject(runtime, exception); | |
+ } | |
} else { | |
- // just rethrow on this thread, let system handlers report it | |
- Helpers.throwException(exception); | |
+ // other Java exceptions we need to propagate | |
+ exitingException = JavaUtil.convertJavaToUsableRubyObject(runtime, exception); | |
+ if (abortOnException(runtime)) { | |
+ | |
+ runtime.getThreadService().getMainThread().raise(new IRubyObject[]{JavaUtil.convertJavaToUsableRubyObject(runtime, exception)}, Block.NULL_BLOCK); | |
+ return; | |
+ } else if (runtime.getDebug().isTrue()) { | |
+ exception.printStackTrace(runtime.getErr()); | |
+ } | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment