Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SI-6905 - Switch to sneakyThrows instead of Unsafe.throwException as …

…per new jsr166y to avoid issues with Android
  • Loading branch information...
commit 57ae1f30b2c6e8f705eea796cd3b36932049b5aa 1 parent ca98602
@viktorklang viktorklang authored
View
2  src/forkjoin/scala/concurrent/forkjoin/ForkJoinPool.java
@@ -1372,7 +1372,7 @@ final void deregisterWorker(ForkJoinWorkerThread wt, Throwable ex) {
}
if (ex != null) // rethrow
- U.throwException(ex);
+ ForkJoinTask.rethrow(ex);
}
View
30 src/forkjoin/scala/concurrent/forkjoin/ForkJoinTask.java
@@ -595,6 +595,30 @@ static final void helpExpungeStaleExceptions() {
}
}
}
+
+ /**
+ * A version of "sneaky throw" to relay exceptions
+ */
+ static void rethrow(final Throwable ex) {
+ if (ex != null) {
+ if (ex instanceof Error)
+ throw (Error)ex;
+ if (ex instanceof RuntimeException)
+ throw (RuntimeException)ex;
+ ForkJoinTask.<RuntimeException>uncheckedThrow(ex);
+ }
+ }
+
+ /**
+ * The sneaky part of sneaky throw, relying on generics
+ * limitations to evade compiler complaints about rethrowing
+ * unchecked exceptions
+ */
+ @SuppressWarnings("unchecked") static <T extends Throwable>
+ void uncheckedThrow(Throwable t) throws T {
+ if (t != null)
+ throw (T)t; // rely on vacuous cast
+ }
/**
* Throws exception, if any, associated with the given status.
@@ -604,7 +628,7 @@ private void reportException(int s) {
(s == EXCEPTIONAL) ? getThrowableException() :
null);
if (ex != null)
- U.throwException(ex);
+ ForkJoinTask.rethrow(ex);
}
// public methods
@@ -742,7 +766,7 @@ else if (t.doJoin() < NORMAL)
}
}
if (ex != null)
- U.throwException(ex);
+ ForkJoinTask.rethrow(ex);
}
/**
@@ -799,7 +823,7 @@ else if (t.doJoin() < NORMAL)
}
}
if (ex != null)
- U.throwException(ex);
+ ForkJoinTask.rethrow(ex);
return tasks;
}
Please sign in to comment.
Something went wrong with that request. Please try again.