diff --git a/java/google/registry/flows/TlsCredentials.java b/java/google/registry/flows/TlsCredentials.java index 95747ffc8..657d1036d 100644 --- a/java/google/registry/flows/TlsCredentials.java +++ b/java/google/registry/flows/TlsCredentials.java @@ -76,7 +76,7 @@ public class TlsCredentials implements TransportCredentials { static InetAddress parseInetAddress(String asciiAddr) { try { - return InetAddresses.forString(HostAndPort.fromString(asciiAddr).getHost()); + return InetAddresses.forString(HostAndPort.fromString(asciiAddr).getHostText()); } catch (IllegalArgumentException e) { return null; } diff --git a/java/google/registry/model/SchemaVersion.java b/java/google/registry/model/SchemaVersion.java index 0d90115a4..d611ffebb 100644 --- a/java/google/registry/model/SchemaVersion.java +++ b/java/google/registry/model/SchemaVersion.java @@ -14,8 +14,8 @@ package google.registry.model; +import static com.google.common.base.Predicates.assignableFrom; import static com.google.common.base.Predicates.or; -import static com.google.common.base.Predicates.subtypeOf; import com.google.common.base.Function; import com.google.common.base.Joiner; @@ -61,7 +61,7 @@ public final class SchemaVersion { */ public static String getSchema() { return FluentIterable.from(getAllPersistedTypes()) - .filter(or(subtypeOf(Enum.class), subtypeOf(ImmutableObject.class))) + .filter(or(assignableFrom(Enum.class), assignableFrom(ImmutableObject.class))) .transform(new Function, String>() { @Override public String apply(Class clazz) { diff --git a/java/google/registry/model/server/Lock.java b/java/google/registry/model/server/Lock.java index 21a84330a..1f4731d83 100644 --- a/java/google/registry/model/server/Lock.java +++ b/java/google/registry/model/server/Lock.java @@ -193,8 +193,7 @@ public class Lock extends ImmutableObject { TimeUnit.MILLISECONDS, true); } catch (Exception e) { - Throwables.throwIfUnchecked(e); - throw new RuntimeException(e); + throw Throwables.propagate(e); } } diff --git a/java/google/registry/request/Router.java b/java/google/registry/request/Router.java index d21df9d29..0349c3d7c 100644 --- a/java/google/registry/request/Router.java +++ b/java/google/registry/request/Router.java @@ -97,7 +97,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.throwIfUnchecked(e.getCause()); + Throwables.propagateIfPossible(e.getCause()); throw new AssertionError( "Component's @Action factory method somehow threw checked exception", e); } diff --git a/java/google/registry/tmch/TmchCertificateAuthority.java b/java/google/registry/tmch/TmchCertificateAuthority.java index cddb08aca..1c7ea6a41 100644 --- a/java/google/registry/tmch/TmchCertificateAuthority.java +++ b/java/google/registry/tmch/TmchCertificateAuthority.java @@ -14,7 +14,7 @@ package google.registry.tmch; -import static com.google.common.base.Throwables.throwIfInstanceOf; +import static com.google.common.base.Throwables.propagateIfInstanceOf; import static google.registry.util.CacheUtils.memoizeWithLongExpiration; import static google.registry.util.CacheUtils.memoizeWithShortExpiration; import static google.registry.util.ResourceUtils.readResourceUtf8; @@ -125,7 +125,7 @@ public final class TmchCertificateAuthority { try { return ROOT_CACHE.get(); } catch (RuntimeException e) { - throwIfInstanceOf(e.getCause(), GeneralSecurityException.class); + propagateIfInstanceOf(e.getCause(), GeneralSecurityException.class); throw e; } } @@ -134,7 +134,7 @@ public final class TmchCertificateAuthority { try { return CRL_CACHE.get(); } catch (RuntimeException e) { - throwIfInstanceOf(e.getCause(), GeneralSecurityException.class); + propagateIfInstanceOf(e.getCause(), GeneralSecurityException.class); throw e; } } diff --git a/java/google/registry/tmch/TmchXmlSignature.java b/java/google/registry/tmch/TmchXmlSignature.java index 55112c549..e50218a00 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.throwIfInstanceOf; +import static com.google.common.base.Throwables.propagateIfInstanceOf; import static google.registry.xml.XmlTransformer.loadXmlSchemas; import com.google.common.collect.ImmutableList; @@ -96,7 +96,7 @@ public final class TmchXmlSignature { isValid = signature.validate(context); } catch (XMLSignatureException e) { Throwable cause = getRootCause(e); - throwIfInstanceOf(cause, GeneralSecurityException.class); + propagateIfInstanceOf(cause, GeneralSecurityException.class); throw e; } if (!isValid) { diff --git a/java/google/registry/tools/AppEngineConnection.java b/java/google/registry/tools/AppEngineConnection.java index 01b29df36..6b4adde3c 100644 --- a/java/google/registry/tools/AppEngineConnection.java +++ b/java/google/registry/tools/AppEngineConnection.java @@ -163,7 +163,7 @@ class AppEngineConnection implements Connection { } boolean isLocalhost() { - return server.getHost().equals("localhost"); + return server.getHostText().equals("localhost"); } private String getUserId() { diff --git a/java/google/registry/tools/RegistryCli.java b/java/google/registry/tools/RegistryCli.java index 7cc7c4330..392a503f8 100644 --- a/java/google/registry/tools/RegistryCli.java +++ b/java/google/registry/tools/RegistryCli.java @@ -129,7 +129,7 @@ final class RegistryCli { // RemoteApiCommands need to have the remote api installed to work. RemoteApiInstaller installer = new RemoteApiInstaller(); RemoteApiOptions options = new RemoteApiOptions(); - options.server(connection.getServer().getHost(), connection.getServer().getPort()); + options.server(connection.getServer().getHostText(), connection.getServer().getPort()); if (connection.isLocalhost()) { // Use dev credentials for localhost. options.useDevelopmentServerCredential(); diff --git a/java/google/registry/util/X509Utils.java b/java/google/registry/util/X509Utils.java index 1e4bdda45..2c0cbfeb6 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.throwIfInstanceOf; +import static com.google.common.base.Throwables.propagateIfInstanceOf; 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. - throwIfInstanceOf(e, CertificateParsingException.class); + propagateIfInstanceOf(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 feb2d7654..50fec54f3 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.throwIfInstanceOf; +import static com.google.common.base.Throwables.propagateIfInstanceOf; 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) { - throwIfInstanceOf(e, MarshalException.class); + propagateIfInstanceOf(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 54860e7b0..77c5c9aef 100644 --- a/javatests/google/registry/server/ServletWrapperDelegatorServlet.java +++ b/javatests/google/registry/server/ServletWrapperDelegatorServlet.java @@ -62,10 +62,9 @@ public final class ServletWrapperDelegatorServlet extends HttpServlet { try { Uninterruptibles.getUninterruptibly(task); } catch (ExecutionException e) { - Throwables.throwIfInstanceOf(e.getCause(), ServletException.class); - Throwables.throwIfInstanceOf(e.getCause(), IOException.class); - Throwables.throwIfUnchecked(e.getCause()); - throw new RuntimeException(e.getCause()); + Throwables.propagateIfInstanceOf(e.getCause(), ServletException.class); + Throwables.propagateIfInstanceOf(e.getCause(), IOException.class); + throw Throwables.propagate(e.getCause()); } } diff --git a/javatests/google/registry/server/TestServer.java b/javatests/google/registry/server/TestServer.java index 4966e5ac5..a5e64ea51 100644 --- a/javatests/google/registry/server/TestServer.java +++ b/javatests/google/registry/server/TestServer.java @@ -91,8 +91,7 @@ public final class TestServer { try { server.start(); } catch (Exception e) { - Throwables.throwIfUnchecked(e); - throw new RuntimeException(e); + throw Throwables.propagate(e); } UrlChecker.waitUntilAvailable(getUrl("/healthz"), STARTUP_TIMEOUT_MS); } @@ -130,8 +129,7 @@ public final class TestServer { } }, SHUTDOWN_TIMEOUT_MS, TimeUnit.MILLISECONDS, true); } catch (Exception e) { - Throwables.throwIfUnchecked(e); - throw new RuntimeException(e); + throw Throwables.propagate(e); } } @@ -168,20 +166,20 @@ public final class TestServer { private static Connector createConnector(HostAndPort address) { SocketConnector connector = new SocketConnector(); - connector.setHost(address.getHost()); + connector.setHost(address.getHostText()); connector.setPort(address.getPortOrDefault(DEFAULT_PORT)); return connector; } /** Converts a bind address into an address that other machines can use to connect here. */ private static HostAndPort createUrlAddress(HostAndPort address) { - if (address.getHost().equals("::") || address.getHost().equals("0.0.0.0")) { + if (address.getHostText().equals("::") || address.getHostText().equals("0.0.0.0")) { return address.getPortOrDefault(DEFAULT_PORT) == DEFAULT_PORT ? HostAndPort.fromHost(getCanonicalHostName()) : HostAndPort.fromParts(getCanonicalHostName(), address.getPort()); } else { return address.getPortOrDefault(DEFAULT_PORT) == DEFAULT_PORT - ? HostAndPort.fromHost(address.getHost()) + ? HostAndPort.fromHost(address.getHostText()) : address; } } diff --git a/javatests/google/registry/server/UrlChecker.java b/javatests/google/registry/server/UrlChecker.java index 09786ca74..8efcfed3e 100644 --- a/javatests/google/registry/server/UrlChecker.java +++ b/javatests/google/registry/server/UrlChecker.java @@ -45,8 +45,7 @@ final class UrlChecker { } }, timeoutMs, TimeUnit.MILLISECONDS, true); } catch (Exception e) { - Throwables.throwIfUnchecked(e); - throw new RuntimeException(e); + throw Throwables.propagate(e); } } diff --git a/javatests/google/registry/tools/params/HostAndPortParameterTest.java b/javatests/google/registry/tools/params/HostAndPortParameterTest.java index 90610bf1f..82de7ae6c 100644 --- a/javatests/google/registry/tools/params/HostAndPortParameterTest.java +++ b/javatests/google/registry/tools/params/HostAndPortParameterTest.java @@ -28,25 +28,25 @@ public class HostAndPortParameterTest { @Test public void testConvert_hostOnly() throws Exception { - assertThat(instance.convert("foo.bar").getHost()).isEqualTo("foo.bar"); + assertThat(instance.convert("foo.bar").getHostText()).isEqualTo("foo.bar"); assertThat(instance.convert("foo.bar").getPortOrDefault(31337)).isEqualTo(31337); } @Test public void testConvert_hostAndPort() throws Exception { - assertThat(instance.convert("foo.bar:1234").getHost()).isEqualTo("foo.bar"); + assertThat(instance.convert("foo.bar:1234").getHostText()).isEqualTo("foo.bar"); assertThat(instance.convert("foo.bar:1234").getPortOrDefault(31337)).isEqualTo(1234); } @Test public void testConvert_ipv6_hostOnly() throws Exception { - assertThat(instance.convert("[feed:a:bee]").getHost()).isEqualTo("feed:a:bee"); + assertThat(instance.convert("[feed:a:bee]").getHostText()).isEqualTo("feed:a:bee"); assertThat(instance.convert("[feed:a:bee]").getPortOrDefault(31337)).isEqualTo(31337); } @Test public void testConvert_ipv6_hostAndPort() throws Exception { - assertThat(instance.convert("[feed:a:bee]:1234").getHost()).isEqualTo("feed:a:bee"); + assertThat(instance.convert("[feed:a:bee]:1234").getHostText()).isEqualTo("feed:a:bee"); assertThat(instance.convert("[feed:a:bee]:1234").getPortOrDefault(31337)).isEqualTo(1234); } }