src/share/classes/java/util/concurrent/ForkJoinTask.java

Print this page




 503     private Throwable getThrowableException() {
 504         if (status != EXCEPTIONAL)
 505             return null;
 506         int h = System.identityHashCode(this);
 507         ExceptionNode e;
 508         final ReentrantLock lock = exceptionTableLock;
 509         lock.lock();
 510         try {
 511             expungeStaleExceptions();
 512             ExceptionNode[] t = exceptionTable;
 513             e = t[h & (t.length - 1)];
 514             while (e != null && e.get() != this)
 515                 e = e.next;
 516         } finally {
 517             lock.unlock();
 518         }
 519         Throwable ex;
 520         if (e == null || (ex = e.ex) == null)
 521             return null;
 522         if (e.thrower != Thread.currentThread().getId()) {
 523             Class ec = ex.getClass();
 524             try {
 525                 Constructor<?> noArgCtor = null;
 526                 Constructor<?>[] cs = ec.getConstructors();// public ctors only
 527                 for (int i = 0; i < cs.length; ++i) {
 528                     Constructor<?> c = cs[i];
 529                     Class<?>[] ps = c.getParameterTypes();
 530                     if (ps.length == 0)
 531                         noArgCtor = c;
 532                     else if (ps.length == 1 && ps[0] == Throwable.class)
 533                         return (Throwable)(c.newInstance(ex));
 534                 }
 535                 if (noArgCtor != null) {
 536                     Throwable wx = (Throwable)(noArgCtor.newInstance());
 537                     wx.initCause(ex);
 538                     return wx;
 539                 }
 540             } catch (Exception ignore) {
 541             }
 542         }
 543         return ex;




 503     private Throwable getThrowableException() {
 504         if (status != EXCEPTIONAL)
 505             return null;
 506         int h = System.identityHashCode(this);
 507         ExceptionNode e;
 508         final ReentrantLock lock = exceptionTableLock;
 509         lock.lock();
 510         try {
 511             expungeStaleExceptions();
 512             ExceptionNode[] t = exceptionTable;
 513             e = t[h & (t.length - 1)];
 514             while (e != null && e.get() != this)
 515                 e = e.next;
 516         } finally {
 517             lock.unlock();
 518         }
 519         Throwable ex;
 520         if (e == null || (ex = e.ex) == null)
 521             return null;
 522         if (e.thrower != Thread.currentThread().getId()) {
 523             Class<? extends Throwable> ec = ex.getClass();
 524             try {
 525                 Constructor<?> noArgCtor = null;
 526                 Constructor<?>[] cs = ec.getConstructors();// public ctors only
 527                 for (int i = 0; i < cs.length; ++i) {
 528                     Constructor<?> c = cs[i];
 529                     Class<?>[] ps = c.getParameterTypes();
 530                     if (ps.length == 0)
 531                         noArgCtor = c;
 532                     else if (ps.length == 1 && ps[0] == Throwable.class)
 533                         return (Throwable)(c.newInstance(ex));
 534                 }
 535                 if (noArgCtor != null) {
 536                     Throwable wx = (Throwable)(noArgCtor.newInstance());
 537                     wx.initCause(ex);
 538                     return wx;
 539                 }
 540             } catch (Exception ignore) {
 541             }
 542         }
 543         return ex;