Replace Throwables.propagate and variants with Guava 20 versions

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=146250470
This commit is contained in:
cgoldfeder 2017-02-01 09:11:42 -08:00 committed by Ben McIlwain
parent a061f74ee7
commit e2e37dc9f3
8 changed files with 25 additions and 20 deletions

View file

@ -15,6 +15,7 @@
package google.registry.model.server; package google.registry.model.server;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Throwables.throwIfUnchecked;
import static com.google.common.collect.Iterables.getFirst; import static com.google.common.collect.Iterables.getFirst;
import static com.google.common.collect.Iterables.skip; import static com.google.common.collect.Iterables.skip;
import static com.google.common.collect.Sets.newLinkedHashSet; import static com.google.common.collect.Sets.newLinkedHashSet;
@ -24,7 +25,6 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DateTimeUtils.isAtOrAfter; import static google.registry.util.DateTimeUtils.isAtOrAfter;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.VoidWork;
@ -193,7 +193,8 @@ public class Lock extends ImmutableObject {
TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS,
true); true);
} catch (Exception e) { } catch (Exception e) {
throw Throwables.propagate(e); throwIfUnchecked(e);
throw new RuntimeException(e);
} }
} }

View file

@ -14,9 +14,10 @@
package google.registry.request; package google.registry.request;
import static com.google.common.base.Throwables.throwIfUnchecked;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -100,7 +101,7 @@ final class Router {
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
// This means an exception was thrown during the injection process while instantiating // This means an exception was thrown during the injection process while instantiating
// the @Action class; we should propagate that underlying exception. // the @Action class; we should propagate that underlying exception.
Throwables.propagateIfPossible(e.getCause()); throwIfUnchecked(e.getCause());
throw new AssertionError( throw new AssertionError(
"Component's @Action factory method somehow threw checked exception", e); "Component's @Action factory method somehow threw checked exception", e);
} }

View file

@ -17,7 +17,7 @@ package google.registry.tmch;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Throwables.getRootCause; import static com.google.common.base.Throwables.getRootCause;
import static com.google.common.base.Throwables.propagateIfInstanceOf; import static com.google.common.base.Throwables.throwIfInstanceOf;
import static google.registry.xml.XmlTransformer.loadXmlSchemas; import static google.registry.xml.XmlTransformer.loadXmlSchemas;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@ -101,8 +101,7 @@ public final class TmchXmlSignature {
try { try {
isValid = signature.validate(context); isValid = signature.validate(context);
} catch (XMLSignatureException e) { } catch (XMLSignatureException e) {
Throwable cause = getRootCause(e); throwIfInstanceOf(getRootCause(e), GeneralSecurityException.class);
propagateIfInstanceOf(cause, GeneralSecurityException.class);
throw e; throw e;
} }
if (!isValid) { if (!isValid) {

View file

@ -16,7 +16,7 @@ package google.registry.util;
import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Throwables.propagateIfInstanceOf; import static com.google.common.base.Throwables.throwIfInstanceOf;
import static com.google.common.io.BaseEncoding.base64; import static com.google.common.io.BaseEncoding.base64;
import static java.nio.charset.StandardCharsets.US_ASCII; import static java.nio.charset.StandardCharsets.US_ASCII;
@ -76,7 +76,7 @@ public final class X509Utils {
.from(CertificateFactory.getInstance("X.509").generateCertificates(input)) .from(CertificateFactory.getInstance("X.509").generateCertificates(input))
.filter(X509Certificate.class)); .filter(X509Certificate.class));
} catch (CertificateException e) { // CertificateParsingException by specification. } catch (CertificateException e) { // CertificateParsingException by specification.
propagateIfInstanceOf(e, CertificateParsingException.class); throwIfInstanceOf(e, CertificateParsingException.class);
throw new CertificateParsingException(e); throw new CertificateParsingException(e);
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
throw new CertificateParsingException("No X509Certificate found."); throw new CertificateParsingException("No X509Certificate found.");

View file

@ -14,7 +14,7 @@
package google.registry.xml; package google.registry.xml;
import static com.google.common.base.Throwables.propagateIfInstanceOf; import static com.google.common.base.Throwables.throwIfInstanceOf;
import static com.google.common.base.Verify.verify; import static com.google.common.base.Verify.verify;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
@ -74,7 +74,7 @@ public final class XmlFragmentMarshaller {
try { try {
marshaller.marshal(element, os); marshaller.marshal(element, os);
} catch (JAXBException e) { } catch (JAXBException e) {
propagateIfInstanceOf(e, MarshalException.class); throwIfInstanceOf(e, MarshalException.class);
throw new RuntimeException("Mysterious XML exception", e); throw new RuntimeException("Mysterious XML exception", e);
} }
String fragment = new String(os.toByteArray(), UTF_8); String fragment = new String(os.toByteArray(), UTF_8);

View file

@ -15,9 +15,9 @@
package google.registry.server; package google.registry.server;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Throwables.throwIfInstanceOf;
import static google.registry.util.TypeUtils.instantiate; import static google.registry.util.TypeUtils.instantiate;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.Uninterruptibles; import com.google.common.util.concurrent.Uninterruptibles;
import java.io.IOException; import java.io.IOException;
@ -86,9 +86,9 @@ public final class ServletWrapperDelegatorServlet extends HttpServlet {
try { try {
Uninterruptibles.getUninterruptibly(task); Uninterruptibles.getUninterruptibly(task);
} catch (ExecutionException e) { } catch (ExecutionException e) {
Throwables.propagateIfInstanceOf(e.getCause(), ServletException.class); throwIfInstanceOf(e.getCause(), ServletException.class);
Throwables.propagateIfInstanceOf(e.getCause(), IOException.class); throwIfInstanceOf(e.getCause(), IOException.class);
throw Throwables.propagate(e.getCause()); throw new RuntimeException(e.getCause());
} }
} }
} }

View file

@ -15,10 +15,10 @@
package google.registry.server; package google.registry.server;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Throwables.throwIfUnchecked;
import static com.google.common.util.concurrent.Runnables.doNothing; import static com.google.common.util.concurrent.Runnables.doNothing;
import static google.registry.util.NetworkUtils.getCanonicalHostName; import static google.registry.util.NetworkUtils.getCanonicalHostName;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.net.HostAndPort; import com.google.common.net.HostAndPort;
import com.google.common.util.concurrent.SimpleTimeLimiter; import com.google.common.util.concurrent.SimpleTimeLimiter;
@ -97,7 +97,8 @@ public final class TestServer {
try { try {
server.start(); server.start();
} catch (Exception e) { } catch (Exception e) {
throw Throwables.propagate(e); throwIfUnchecked(e);
throw new RuntimeException(e);
} }
UrlChecker.waitUntilAvailable(getUrl("/healthz"), STARTUP_TIMEOUT_MS); UrlChecker.waitUntilAvailable(getUrl("/healthz"), STARTUP_TIMEOUT_MS);
} }
@ -135,7 +136,8 @@ public final class TestServer {
} }
}, SHUTDOWN_TIMEOUT_MS, TimeUnit.MILLISECONDS, true); }, SHUTDOWN_TIMEOUT_MS, TimeUnit.MILLISECONDS, true);
} catch (Exception e) { } catch (Exception e) {
throw Throwables.propagate(e); throwIfUnchecked(e);
throw new RuntimeException(e);
} }
} }

View file

@ -14,7 +14,8 @@
package google.registry.server; package google.registry.server;
import com.google.common.base.Throwables; import static com.google.common.base.Throwables.throwIfUnchecked;
import com.google.common.util.concurrent.SimpleTimeLimiter; import com.google.common.util.concurrent.SimpleTimeLimiter;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
@ -45,7 +46,8 @@ final class UrlChecker {
} }
}, timeoutMs, TimeUnit.MILLISECONDS, true); }, timeoutMs, TimeUnit.MILLISECONDS, true);
} catch (Exception e) { } catch (Exception e) {
throw Throwables.propagate(e); throwIfUnchecked(e);
throw new RuntimeException(e);
} }
} }