test/java/util/concurrent/FutureTask/Throw.java

Print this page




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6415572
  27  * @summary Check exceptional behavior in run and done methods
  28  */
  29 
  30 import java.util.concurrent.*;


  31 
  32 public class Throw {










  33 
  34     @SuppressWarnings("deprecation")
  35     static void THROW(final Throwable t) {
  36         if (t != null)
  37             Thread.currentThread().stop(t);
  38     }
  39 
  40     Callable<Void> thrower(final Throwable t) {
  41         return new Callable<Void>() { public Void call() {
  42             THROW(t); return null; }};
  43     }
  44 
  45     @SuppressWarnings("serial")
  46     private static class DoneError extends Error {}
  47 
  48     @SuppressWarnings("serial")
  49     private static class DoneException extends RuntimeException {}
  50 
  51     static class MyFutureTask extends FutureTask<Void> {
  52         MyFutureTask(Callable<Void> task) { super(task); }
  53         public boolean runAndReset() { return super.runAndReset(); }
  54     }
  55 
  56     MyFutureTask checkTask(final MyFutureTask task) {
  57         check(! task.isCancelled());




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6415572
  27  * @summary Check exceptional behavior in run and done methods
  28  */
  29 
  30 import java.util.concurrent.*;
  31 import java.lang.reflect.Field;
  32 import sun.misc.Unsafe;
  33 
  34 public class Throw {
  35     private static final Unsafe UNSAFE;
  36     static {
  37         try {
  38             Field f = Unsafe.class.getDeclaredField("theUnsafe");
  39             f.setAccessible(true);
  40             UNSAFE = (Unsafe)f.get(null);
  41         } catch (NoSuchFieldException | IllegalAccessException e) {
  42             throw new RuntimeException(e);
  43         }
  44     }
  45 
  46     @SuppressWarnings("deprecation")
  47     static void THROW(final Throwable t) {
  48         if (t != null)
  49             UNSAFE.throwException(t);
  50     }
  51 
  52     Callable<Void> thrower(final Throwable t) {
  53         return new Callable<Void>() { public Void call() {
  54             THROW(t); return null; }};
  55     }
  56 
  57     @SuppressWarnings("serial")
  58     private static class DoneError extends Error {}
  59 
  60     @SuppressWarnings("serial")
  61     private static class DoneException extends RuntimeException {}
  62 
  63     static class MyFutureTask extends FutureTask<Void> {
  64         MyFutureTask(Callable<Void> task) { super(task); }
  65         public boolean runAndReset() { return super.runAndReset(); }
  66     }
  67 
  68     MyFutureTask checkTask(final MyFutureTask task) {
  69         check(! task.isCancelled());