diff --git a/java/google/registry/model/server/Lock.java b/java/google/registry/model/server/Lock.java index 79edbe6c8..51a25d20e 100644 --- a/java/google/registry/model/server/Lock.java +++ b/java/google/registry/model/server/Lock.java @@ -15,6 +15,7 @@ package google.registry.model.server; 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.skip; 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 com.google.common.base.Strings; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSortedSet; import com.googlecode.objectify.VoidWork; @@ -193,7 +193,8 @@ public class Lock extends ImmutableObject { TimeUnit.MILLISECONDS, true); } catch (Exception e) { - throw Throwables.propagate(e); + throwIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/java/google/registry/request/Router.java b/java/google/registry/request/Router.java index fe659ecbd..c3a7e9e90 100644 --- a/java/google/registry/request/Router.java +++ b/java/google/registry/request/Router.java @@ -14,9 +14,10 @@ package google.registry.request; +import static com.google.common.base.Throwables.throwIfUnchecked; + import com.google.common.base.Function; import com.google.common.base.Optional; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Ordering; import java.lang.reflect.InvocationTargetException; @@ -100,7 +101,7 @@ final class Router { } catch (InvocationTargetException e) { // This means an exception was thrown during the injection process while instantiating // the @Action class; we should propagate that underlying exception. - Throwables.propagateIfPossible(e.getCause()); + throwIfUnchecked(e.getCause()); throw new AssertionError( "Component's @Action factory method somehow threw checked exception", e); } diff --git a/java/google/registry/tmch/TmchXmlSignature.java b/java/google/registry/tmch/TmchXmlSignature.java index 14d9d92af..64f882328 100644 --- a/java/google/registry/tmch/TmchXmlSignature.java +++ b/java/google/registry/tmch/TmchXmlSignature.java @@ -17,7 +17,7 @@ package google.registry.tmch; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; 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 com.google.common.annotations.VisibleForTesting; @@ -101,8 +101,7 @@ public final class TmchXmlSignature { try { isValid = signature.validate(context); } catch (XMLSignatureException e) { - Throwable cause = getRootCause(e); - propagateIfInstanceOf(cause, GeneralSecurityException.class); + throwIfInstanceOf(getRootCause(e), GeneralSecurityException.class); throw e; } if (!isValid) { diff --git a/java/google/registry/util/X509Utils.java b/java/google/registry/util/X509Utils.java index 029d28773..e77c897a9 100644 --- a/java/google/registry/util/X509Utils.java +++ b/java/google/registry/util/X509Utils.java @@ -16,7 +16,7 @@ package google.registry.util; import static com.google.common.base.MoreObjects.firstNonNull; 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 java.nio.charset.StandardCharsets.US_ASCII; @@ -76,7 +76,7 @@ public final class X509Utils { .from(CertificateFactory.getInstance("X.509").generateCertificates(input)) .filter(X509Certificate.class)); } catch (CertificateException e) { // CertificateParsingException by specification. - propagateIfInstanceOf(e, CertificateParsingException.class); + throwIfInstanceOf(e, CertificateParsingException.class); throw new CertificateParsingException(e); } catch (NoSuchElementException e) { throw new CertificateParsingException("No X509Certificate found."); diff --git a/java/google/registry/xml/XmlFragmentMarshaller.java b/java/google/registry/xml/XmlFragmentMarshaller.java index c8e02e707..52d94ef33 100644 --- a/java/google/registry/xml/XmlFragmentMarshaller.java +++ b/java/google/registry/xml/XmlFragmentMarshaller.java @@ -14,7 +14,7 @@ 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 java.nio.charset.StandardCharsets.UTF_8; @@ -74,7 +74,7 @@ public final class XmlFragmentMarshaller { try { marshaller.marshal(element, os); } catch (JAXBException e) { - propagateIfInstanceOf(e, MarshalException.class); + throwIfInstanceOf(e, MarshalException.class); throw new RuntimeException("Mysterious XML exception", e); } String fragment = new String(os.toByteArray(), UTF_8); diff --git a/javatests/google/registry/server/ServletWrapperDelegatorServlet.java b/javatests/google/registry/server/ServletWrapperDelegatorServlet.java index 28e31043d..d0ae0650c 100644 --- a/javatests/google/registry/server/ServletWrapperDelegatorServlet.java +++ b/javatests/google/registry/server/ServletWrapperDelegatorServlet.java @@ -15,9 +15,9 @@ package google.registry.server; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Throwables.throwIfInstanceOf; import static google.registry.util.TypeUtils.instantiate; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.Uninterruptibles; import java.io.IOException; @@ -86,9 +86,9 @@ public final class ServletWrapperDelegatorServlet extends HttpServlet { try { Uninterruptibles.getUninterruptibly(task); } catch (ExecutionException e) { - Throwables.propagateIfInstanceOf(e.getCause(), ServletException.class); - Throwables.propagateIfInstanceOf(e.getCause(), IOException.class); - throw Throwables.propagate(e.getCause()); + throwIfInstanceOf(e.getCause(), ServletException.class); + throwIfInstanceOf(e.getCause(), IOException.class); + throw new RuntimeException(e.getCause()); } } } diff --git a/javatests/google/registry/server/TestServer.java b/javatests/google/registry/server/TestServer.java index 2780446d6..9cf4502ed 100644 --- a/javatests/google/registry/server/TestServer.java +++ b/javatests/google/registry/server/TestServer.java @@ -15,10 +15,10 @@ package google.registry.server; 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 google.registry.util.NetworkUtils.getCanonicalHostName; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.net.HostAndPort; import com.google.common.util.concurrent.SimpleTimeLimiter; @@ -97,7 +97,8 @@ public final class TestServer { try { server.start(); } catch (Exception e) { - throw Throwables.propagate(e); + throwIfUnchecked(e); + throw new RuntimeException(e); } UrlChecker.waitUntilAvailable(getUrl("/healthz"), STARTUP_TIMEOUT_MS); } @@ -135,7 +136,8 @@ public final class TestServer { } }, SHUTDOWN_TIMEOUT_MS, TimeUnit.MILLISECONDS, true); } catch (Exception e) { - throw Throwables.propagate(e); + throwIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/javatests/google/registry/server/UrlChecker.java b/javatests/google/registry/server/UrlChecker.java index d54e2328f..9aac6c5e5 100644 --- a/javatests/google/registry/server/UrlChecker.java +++ b/javatests/google/registry/server/UrlChecker.java @@ -14,7 +14,8 @@ 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 java.io.IOException; import java.net.HttpURLConnection; @@ -45,7 +46,8 @@ final class UrlChecker { } }, timeoutMs, TimeUnit.MILLISECONDS, true); } catch (Exception e) { - throw Throwables.propagate(e); + throwIfUnchecked(e); + throw new RuntimeException(e); } }