JVMUtil { public static Exception runAndGetExecutionException(final Runnable runnable) { final MutableObject<Exception> ex = new MutableObject<Exception>(); Thread thread = new Thread() { @Override public void run() { try { runnable.run(); } catch ( Exception e ) { Log.error( e.getMessage(), e ); ex.set( e ); } } }; thread.start(); Uninterruptibles.joinUninterruptibly( thread ); if ( ex.get() == null ) throw new AssertionError( "there is no exception!" ); return ex.get(); } private  JVMUtil(); static void gc(); static void gcOnExit(); static Field fieldFor(final Class<?> clazz,
                                 final String name); @SuppressWarnings("unchecked") static T getPropertyValueUnsafe(final Object source,
                                               final Class<T> valueType,
                                               final long fieldOffset); static void setPropertyValueUnsafe(final Object source,
                                                  final T value,
                                                  final Class<T> valueType,
                                                  final long fieldOffset); static Exception runAndGetExecutionException(final Runnable runnable); static List<Throwable> repeatConcurrently(final int threads,
                                                         final int totalIterationsCount,
                                                         final Function<Integer, Object> task); static List<Throwable> repeatConcurrently(final int threads,
                                                         final int totalIterationsCount,
                                                         final Runnable task); static int murmurRehash(final int hash); static int jdkRehash(final int hash); static boolean equals(final Object o1,
                                 final Object o2); static void ensureEnoughMemoryCapacity(final ByteArrayPointer pointer,
                                                  final CapacityRestriction capacityRestriction,
                                                  final Sequence memoryUsed); static void ensureEnoughCapacity(final Object obj,
                                            final CapacityRestriction capacityRestriction,
                                            final Sequence itemsCount);  }
@Test public void canRunAndGetException() { assertThat( JVMUtil.runAndGetExecutionException( new Runnable() { @Override public void run() { throw new NullPointerException(); } } ), is( notNullValue() ) ); }
@Test(expected = AssertionError.class) public void canRunAndDidntGetException() { JVMUtil.runAndGetExecutionException( new Runnable() { @Override public void run() { ObjectBuffer borrowObject = new ObjectBuffer( new Kryo() ); borrowObject.setKryo( new Kryo() ); } } ); }