From 241abea734b8b3354c82a2241c93ec04cc6bbf3c Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Wed, 29 Jan 2014 09:02:39 -0800 Subject: [PATCH] Store propagatable exceptions in a static field Also include ResourceAlreadyExistsException. References JCLOUDS-438. --- .../java/org/jclouds/util/Throwables2.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/jclouds/util/Throwables2.java b/core/src/main/java/org/jclouds/util/Throwables2.java index 309153e2de..cf0e9b1ff6 100644 --- a/core/src/main/java/org/jclouds/util/Throwables2.java +++ b/core/src/main/java/org/jclouds/util/Throwables2.java @@ -27,10 +27,12 @@ import org.jclouds.concurrent.TransformParallelException; import org.jclouds.http.HttpResponseException; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.InsufficientResourcesException; +import org.jclouds.rest.ResourceAlreadyExistsException; import org.jclouds.rest.ResourceNotFoundException; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableList; import com.google.common.reflect.TypeToken; import com.google.inject.CreationException; import com.google.inject.ProvisionException; @@ -125,8 +127,19 @@ public class Throwables2 { return null; } + // Note that ordering matters to propagateIfPossible. + private static final ImmutableList> PROPAGATABLE_EXCEPTION_TYPES = ImmutableList.of( + IllegalStateException.class, + AssertionError.class, + UnsupportedOperationException.class, + IllegalArgumentException.class, + AuthorizationException.class, + ResourceAlreadyExistsException.class, + ResourceNotFoundException.class, + InsufficientResourcesException.class, + HttpResponseException.class); + // Note this needs to be kept up-to-date with all top-level exceptions jclouds works against - @SuppressWarnings("unchecked") public static void propagateIfPossible(Throwable exception, Iterable> throwables) throws Throwable { for (TypeToken type : throwables) { @@ -135,10 +148,7 @@ public class Throwables2 { throw throwable; } } - for (Class propagatableExceptionType : new Class[] { IllegalStateException.class, - AssertionError.class, UnsupportedOperationException.class, IllegalArgumentException.class, - AuthorizationException.class, ResourceNotFoundException.class, InsufficientResourcesException.class, - HttpResponseException.class }) { + for (Class propagatableExceptionType : PROPAGATABLE_EXCEPTION_TYPES) { Throwable throwable = Throwables2.getFirstThrowableOfType(exception, propagatableExceptionType); if (throwable != null) { throw throwable;