Improve use of Throwables.propagate

Throwing the return value removes some unneeded asserts and return
statements.  Also remove some useless and misspelled propogate
wrappers.
This commit is contained in:
Andrew Gaul 2012-05-02 10:53:47 -07:00
parent 42d57c5d15
commit 646f8d8b13
11 changed files with 27 additions and 67 deletions

View File

@ -262,9 +262,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
.build())); .build()));
return metadata; return metadata;
} catch (Exception e) { } catch (Exception e) {
propagate(e); throw propagate(e);
assert false : "exception should have propagated: " + e;
return null;
} }
} }

View File

@ -122,9 +122,7 @@ public abstract class BindCloneParamsToXmlPayload<O extends CloneOptions> implem
try { try {
return getOptionClass().newInstance(); return getOptionClass().newInstance();
} catch (Exception e) { } catch (Exception e) {
Throwables.propagate(e); throw Throwables.propagate(e);
assert false : "unreachable code";
return null;
} }
} }

View File

@ -251,9 +251,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
HttpUtils.copy(in.getContentMetadata(), out.getContentMetadata()); HttpUtils.copy(in.getContentMetadata(), out.getContentMetadata());
return out; return out;
} catch (Exception e) { } catch (Exception e) {
propagate(e); throw propagate(e);
assert false : "exception should have propagated: " + e;
return null;
} }
} }

View File

@ -48,9 +48,7 @@ public class RetryOnTimeOutExceptionSupplier<T> implements Supplier<T> {
} catch (Exception e) { } catch (Exception e) {
if ((ex = Throwables2.getFirstThrowableOfType(e, TimeoutException.class)) != null) if ((ex = Throwables2.getFirstThrowableOfType(e, TimeoutException.class)) != null)
continue; continue;
propagate(e); throw propagate(e);
assert false;
return null;
} }
} }
if (ex != null) if (ex != null)

View File

@ -115,8 +115,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
in = bufferAndCloseStream(connection.getErrorStream()); in = bufferAndCloseStream(connection.getErrorStream());
} catch (RuntimeException e) { } catch (RuntimeException e) {
closeQuietly(in); closeQuietly(in);
propagate(e); throw propagate(e);
assert false : "should have propagated exception";
} }
int responseCode = connection.getResponseCode(); int responseCode = connection.getResponseCode();

View File

@ -56,9 +56,7 @@ public class SetAndThrowAuthorizationExceptionSupplier<T> implements Supplier<T>
authException.set(aex); authException.set(aex);
throw aex; throw aex;
} }
propagate(e); throw propagate(e);
assert false : e;
return null;
} }
} }

View File

@ -84,8 +84,7 @@ public class RetrieveActiveBridgedInterfaces implements Function<NodeMetadata, L
} }
} catch (SocketException e) { } catch (SocketException e) {
logger.error(e, "Problem in listing network interfaces."); logger.error(e, "Problem in listing network interfaces.");
Throwables.propagate(e); throw Throwables.propagate(e);
assert false;
} }
return activeNetworkInterfaces; return activeNetworkInterfaces;
} }
@ -117,10 +116,8 @@ public class RetrieveActiveBridgedInterfaces implements Function<NodeMetadata, L
!networkInterface.isLoopback()); !networkInterface.isLoopback());
} catch (SocketException e) { } catch (SocketException e) {
logger.error(e, "Problem in listing network interfaces."); logger.error(e, "Problem in listing network interfaces.");
Throwables.propagate(e); throw Throwables.propagate(e);
assert false;
} }
return false;
} }
} }
} }

View File

@ -115,14 +115,7 @@ public class LibvirtComputeService extends BaseComputeService {
storageVol.delete(0); storageVol.delete(0);
client.domainLookupByUUIDString(id).undefine(); client.domainLookupByUUIDString(id).undefine();
} catch (Exception e) { } catch (Exception e) {
propogate(e); Throwables.propagate(e);
} }
} }
protected <T> T propogate(Exception e) {
Throwables.propagate(e);
assert false;
return null;
}
} }

View File

@ -83,22 +83,16 @@ public class DomainToHardware implements Function<Domain, Hardware> {
} }
builder.volumes((List<Volume>) volumes); builder.volumes((List<Volume>) volumes);
} catch (LibvirtException e) { } catch (LibvirtException e) {
propagate(e); Throwables.propagate(e);
} catch (XPathExpressionException e) { } catch (XPathExpressionException e) {
propagate(e); Throwables.propagate(e);
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
propagate(e); Throwables.propagate(e);
} catch (SAXException e) { } catch (SAXException e) {
propagate(e); Throwables.propagate(e);
} catch (IOException e) { } catch (IOException e) {
propagate(e); Throwables.propagate(e);
} }
return builder.build(); return builder.build();
} }
protected <T> T propagate(Exception e) {
Throwables.propagate(e);
assert false;
return null;
}
} }

View File

@ -116,9 +116,9 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
credentialStore.put(domain.getUUIDString() + "", new Credentials("identity", "credential")); credentialStore.put(domain.getUUIDString() + "", new Credentials("identity", "credential"));
return newDomain; return newDomain;
} catch (LibvirtException e) { } catch (LibvirtException e) {
return propogate(e); throw Throwables.propagate(e);
} catch (Exception e) { } catch (Exception e) {
return propogate(e); throw Throwables.propagate(e);
} }
} }
@ -138,7 +138,7 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
} }
return images; return images;
} catch (Exception e) { } catch (Exception e) {
return propogate(e); throw Throwables.propagate(e);
} }
} }
@ -151,7 +151,7 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
} }
return domains; return domains;
} catch (LibvirtException e) { } catch (LibvirtException e) {
return propogate(e); throw Throwables.propagate(e);
} }
} }
@ -168,7 +168,7 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
} catch (LibvirtException e) { } catch (LibvirtException e) {
if (e.getMessage().indexOf("Domain not found: no domain with matching uuid") != -1) if (e.getMessage().indexOf("Domain not found: no domain with matching uuid") != -1)
return null; return null;
propogate(e); Throwables.propagate(e);
} }
return d; return d;
} }
@ -187,9 +187,9 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
client.domainLookupByUUIDString(id).undefine(); client.domainLookupByUUIDString(id).undefine();
} catch (LibvirtException e) { } catch (LibvirtException e) {
propogate(e); Throwables.propagate(e);
} catch (Exception e) { } catch (Exception e) {
propogate(e); Throwables.propagate(e);
} }
} }
@ -198,22 +198,10 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
try { try {
client.domainLookupByUUIDString(id).reboot(0); client.domainLookupByUUIDString(id).reboot(0);
} catch (LibvirtException e) { } catch (LibvirtException e) {
propogate(e); Throwables.propagate(e);
} }
} }
protected <T> T propogate(LibvirtException e) {
Throwables.propagate(e);
assert false;
return null;
}
protected <T> T propogate(Exception e) {
Throwables.propagate(e);
assert false;
return null;
}
private static StorageVol cloneVolume(StoragePool storagePool, StorageVol from) throws LibvirtException, private static StorageVol cloneVolume(StoragePool storagePool, StorageVol from) throws LibvirtException,
XPathExpressionException, ParserConfigurationException, SAXException, IOException, TransformerException { XPathExpressionException, ParserConfigurationException, SAXException, IOException, TransformerException {
return storagePool.storageVolCreateXMLFrom(generateClonedVolumeXML(from.getXMLDesc(0)), from, 0); return storagePool.storageVolCreateXMLFrom(generateClonedVolumeXML(from.getXMLDesc(0)), from, 0);
@ -224,7 +212,7 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
try { try {
client.domainLookupByUUIDString(id).resume(); client.domainLookupByUUIDString(id).resume();
} catch (LibvirtException e) { } catch (LibvirtException e) {
propogate(e); Throwables.propagate(e);
} }
} }
@ -233,7 +221,7 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
try { try {
client.domainLookupByUUIDString(id).suspend(); client.domainLookupByUUIDString(id).suspend();
} catch (LibvirtException e) { } catch (LibvirtException e) {
propogate(e); Throwables.propagate(e);
} }
} }

View File

@ -192,8 +192,7 @@ public class NingHttpCommandExecutorService implements HttpCommandExecutorServic
in = BaseHttpCommandExecutorService.consumeOnClose(nativeResponse.getResponseBodyAsStream()); in = BaseHttpCommandExecutorService.consumeOnClose(nativeResponse.getResponseBodyAsStream());
} catch (IOException e) { } catch (IOException e) {
Closeables.closeQuietly(in); Closeables.closeQuietly(in);
propagate(e); throw propagate(e);
assert false : "should have propagated exception";
} }
Payload payload = in != null ? Payloads.newInputStreamPayload(in) : null; Payload payload = in != null ? Payloads.newInputStreamPayload(in) : null;