@Test public void testVerifyCaller() { class A implements Callable<Object> { @SuppressWarnings("unused") @Override public Object call() throws IOException, InterruptedException { return null; } } class B extends A { } class C extends A { @SuppressWarnings("unused") @Override public Object call() throws FileNotFoundException { return null; } } class D extends C { @Override public Object call() throws IllegalArgumentException { return null; } } class E extends A { @Override public String call() throws NullPointerException { return null; } } class F extends A { @Override public Object call() throws Error { return null; } } ExceptionHandler handler = ExceptionHandler.getDefaultInstance(); assertValidCallable(new A(), handler); assertValidCallable(new B(), handler); assertValidCallable(new C(), handler); assertValidCallable(new D(), handler); assertValidCallable(new E(), handler); assertInvalidCallable(new F(), handler); handler = new ExceptionHandler.Builder().retryOn( FileNotFoundException.class, NullPointerException.class).build(); assertInvalidCallable(new A(), handler); assertInvalidCallable(new B(), handler); assertValidCallable(new C(), handler); assertInvalidCallable(new D(), handler); assertValidCallable(new E(), handler); assertInvalidCallable(new F(), handler); }
void verifyCaller(Callable<?> callable) { Method callMethod = getCallableMethod(callable.getClass()); for (Class<?> exceptionOrError : callMethod.getExceptionTypes()) { Preconditions.checkArgument(Exception.class.isAssignableFrom(exceptionOrError), "Callable method exceptions must be dervied from Exception"); @SuppressWarnings("unchecked") Class<? extends Exception> exception = (Class<? extends Exception>) exceptionOrError; Preconditions.checkArgument(findMostSpecificRetryInfo(retryInfos, exception) != null, "Declared exception '" + exception + "' is not covered by exception handler"); } }
ExceptionHandler implements Serializable { void verifyCaller(Callable<?> callable) { Method callMethod = getCallableMethod(callable.getClass()); for (Class<?> exceptionOrError : callMethod.getExceptionTypes()) { Preconditions.checkArgument(Exception.class.isAssignableFrom(exceptionOrError), "Callable method exceptions must be dervied from Exception"); @SuppressWarnings("unchecked") Class<? extends Exception> exception = (Class<? extends Exception>) exceptionOrError; Preconditions.checkArgument(findMostSpecificRetryInfo(retryInfos, exception) != null, "Declared exception '" + exception + "' is not covered by exception handler"); } } }
ExceptionHandler implements Serializable { void verifyCaller(Callable<?> callable) { Method callMethod = getCallableMethod(callable.getClass()); for (Class<?> exceptionOrError : callMethod.getExceptionTypes()) { Preconditions.checkArgument(Exception.class.isAssignableFrom(exceptionOrError), "Callable method exceptions must be dervied from Exception"); @SuppressWarnings("unchecked") Class<? extends Exception> exception = (Class<? extends Exception>) exceptionOrError; Preconditions.checkArgument(findMostSpecificRetryInfo(retryInfos, exception) != null, "Declared exception '" + exception + "' is not covered by exception handler"); } } private  ExceptionHandler(Builder builder); }
ExceptionHandler implements Serializable { void verifyCaller(Callable<?> callable) { Method callMethod = getCallableMethod(callable.getClass()); for (Class<?> exceptionOrError : callMethod.getExceptionTypes()) { Preconditions.checkArgument(Exception.class.isAssignableFrom(exceptionOrError), "Callable method exceptions must be dervied from Exception"); @SuppressWarnings("unchecked") Class<? extends Exception> exception = (Class<? extends Exception>) exceptionOrError; Preconditions.checkArgument(findMostSpecificRetryInfo(retryInfos, exception) != null, "Declared exception '" + exception + "' is not covered by exception handler"); } } private  ExceptionHandler(Builder builder); ImmutableSet<Class<? extends Exception>> getRetriableExceptions(); ImmutableSet<Class<? extends Exception>> getNonRetriableExceptions(); static ExceptionHandler getDefaultInstance(); }
ExceptionHandler implements Serializable { void verifyCaller(Callable<?> callable) { Method callMethod = getCallableMethod(callable.getClass()); for (Class<?> exceptionOrError : callMethod.getExceptionTypes()) { Preconditions.checkArgument(Exception.class.isAssignableFrom(exceptionOrError), "Callable method exceptions must be dervied from Exception"); @SuppressWarnings("unchecked") Class<? extends Exception> exception = (Class<? extends Exception>) exceptionOrError; Preconditions.checkArgument(findMostSpecificRetryInfo(retryInfos, exception) != null, "Declared exception '" + exception + "' is not covered by exception handler"); } } private  ExceptionHandler(Builder builder); ImmutableSet<Class<? extends Exception>> getRetriableExceptions(); ImmutableSet<Class<? extends Exception>> getNonRetriableExceptions(); static ExceptionHandler getDefaultInstance();  }