@Test
public void testUnobservedError() throws InterruptedException {

  try {
    final Object sync = new Object();
    Task.setUnobservedExceptionHandler(new Task.UnobservedExceptionHandler() {
      @Override
      public void unobservedException(Task<?> t, UnobservedTaskException e) {
        synchronized (sync) {
          sync.notify();
        }
      }
    });
    synchronized (sync) {
      startFailedTask();
      System.gc();
      sync.wait();
    }
  } finally {
    Task.setUnobservedExceptionHandler(null);
  }
}