From 646f8d8b13daceb302a0cc52751f0b4d34ac533b Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Wed, 2 May 2012 10:53:47 -0700 Subject: [PATCH] Improve use of Throwables.propagate Throwing the return value removes some unneeded asserts and return statements. Also remove some useless and misspelled propogate wrappers. --- .../filesystem/FilesystemAsyncBlobStore.java | 4 +-- .../binders/BindCloneParamsToXmlPayload.java | 4 +-- .../blobstore/TransientAsyncBlobStore.java | 4 +-- .../RetryOnTimeOutExceptionSupplier.java | 4 +-- .../JavaUrlHttpCommandExecutorService.java | 3 +- ...ndThrowAuthorizationExceptionSupplier.java | 4 +-- .../RetrieveActiveBridgedInterfaces.java | 9 ++---- .../compute/LibvirtComputeService.java | 9 +----- .../compute/functions/DomainToHardware.java | 18 ++++------- .../LibvirtComputeServiceAdapter.java | 32 ++++++------------- .../ning/NingHttpCommandExecutorService.java | 3 +- 11 files changed, 27 insertions(+), 67 deletions(-) diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java index 7c828ec7ff..412cf2d326 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java @@ -262,9 +262,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore { .build())); return metadata; } catch (Exception e) { - propagate(e); - assert false : "exception should have propagated: " + e; - return null; + throw propagate(e); } } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/binders/BindCloneParamsToXmlPayload.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/binders/BindCloneParamsToXmlPayload.java index 6fb9d55cd9..9241d53e26 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/binders/BindCloneParamsToXmlPayload.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/binders/BindCloneParamsToXmlPayload.java @@ -122,9 +122,7 @@ public abstract class BindCloneParamsToXmlPayload implem try { return getOptionClass().newInstance(); } catch (Exception e) { - Throwables.propagate(e); - assert false : "unreachable code"; - return null; + throw Throwables.propagate(e); } } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java index d01f168855..629b7b4d1e 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java @@ -251,9 +251,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { HttpUtils.copy(in.getContentMetadata(), out.getContentMetadata()); return out; } catch (Exception e) { - propagate(e); - assert false : "exception should have propagated: " + e; - return null; + throw propagate(e); } } diff --git a/core/src/main/java/org/jclouds/concurrent/RetryOnTimeOutExceptionSupplier.java b/core/src/main/java/org/jclouds/concurrent/RetryOnTimeOutExceptionSupplier.java index 5c4b7c6a2e..c908c13d3f 100644 --- a/core/src/main/java/org/jclouds/concurrent/RetryOnTimeOutExceptionSupplier.java +++ b/core/src/main/java/org/jclouds/concurrent/RetryOnTimeOutExceptionSupplier.java @@ -48,9 +48,7 @@ public class RetryOnTimeOutExceptionSupplier implements Supplier { } catch (Exception e) { if ((ex = Throwables2.getFirstThrowableOfType(e, TimeoutException.class)) != null) continue; - propagate(e); - assert false; - return null; + throw propagate(e); } } if (ex != null) diff --git a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java index 21108564c5..065c1f23d0 100644 --- a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java @@ -115,8 +115,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe in = bufferAndCloseStream(connection.getErrorStream()); } catch (RuntimeException e) { closeQuietly(in); - propagate(e); - assert false : "should have propagated exception"; + throw propagate(e); } int responseCode = connection.getResponseCode(); diff --git a/core/src/main/java/org/jclouds/rest/suppliers/SetAndThrowAuthorizationExceptionSupplier.java b/core/src/main/java/org/jclouds/rest/suppliers/SetAndThrowAuthorizationExceptionSupplier.java index d32070be41..412d85577a 100644 --- a/core/src/main/java/org/jclouds/rest/suppliers/SetAndThrowAuthorizationExceptionSupplier.java +++ b/core/src/main/java/org/jclouds/rest/suppliers/SetAndThrowAuthorizationExceptionSupplier.java @@ -56,9 +56,7 @@ public class SetAndThrowAuthorizationExceptionSupplier implements Supplier authException.set(aex); throw aex; } - propagate(e); - assert false : e; - return null; + throw propagate(e); } } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/RetrieveActiveBridgedInterfaces.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/RetrieveActiveBridgedInterfaces.java index 0cd9fc327c..81ffd7bc5d 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/RetrieveActiveBridgedInterfaces.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/RetrieveActiveBridgedInterfaces.java @@ -84,8 +84,7 @@ public class RetrieveActiveBridgedInterfaces implements Function T propogate(Exception e) { - Throwables.propagate(e); - assert false; - return null; - } - } diff --git a/sandbox-apis/libvirt/src/main/java/org/jclouds/libvirt/compute/functions/DomainToHardware.java b/sandbox-apis/libvirt/src/main/java/org/jclouds/libvirt/compute/functions/DomainToHardware.java index e6b092966d..75996727a4 100644 --- a/sandbox-apis/libvirt/src/main/java/org/jclouds/libvirt/compute/functions/DomainToHardware.java +++ b/sandbox-apis/libvirt/src/main/java/org/jclouds/libvirt/compute/functions/DomainToHardware.java @@ -83,22 +83,16 @@ public class DomainToHardware implements Function { } builder.volumes((List) volumes); } catch (LibvirtException e) { - propagate(e); + Throwables.propagate(e); } catch (XPathExpressionException e) { - propagate(e); + Throwables.propagate(e); } catch (ParserConfigurationException e) { - propagate(e); + Throwables.propagate(e); } catch (SAXException e) { - propagate(e); + Throwables.propagate(e); } catch (IOException e) { - propagate(e); + Throwables.propagate(e); } return builder.build(); } - - protected T propagate(Exception e) { - Throwables.propagate(e); - assert false; - return null; - } -} \ No newline at end of file +} diff --git a/sandbox-apis/libvirt/src/main/java/org/jclouds/libvirt/compute/strategy/LibvirtComputeServiceAdapter.java b/sandbox-apis/libvirt/src/main/java/org/jclouds/libvirt/compute/strategy/LibvirtComputeServiceAdapter.java index 732ac72c08..cde06ea53d 100644 --- a/sandbox-apis/libvirt/src/main/java/org/jclouds/libvirt/compute/strategy/LibvirtComputeServiceAdapter.java +++ b/sandbox-apis/libvirt/src/main/java/org/jclouds/libvirt/compute/strategy/LibvirtComputeServiceAdapter.java @@ -116,9 +116,9 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter T propogate(LibvirtException e) { - Throwables.propagate(e); - assert false; - return null; - } - - protected T propogate(Exception e) { - Throwables.propagate(e); - assert false; - return null; - } - private static StorageVol cloneVolume(StoragePool storagePool, StorageVol from) throws LibvirtException, XPathExpressionException, ParserConfigurationException, SAXException, IOException, TransformerException { return storagePool.storageVolCreateXMLFrom(generateClonedVolumeXML(from.getXMLDesc(0)), from, 0); @@ -224,7 +212,7 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter