diff --git a/java/google/registry/flows/TlsCredentials.java b/java/google/registry/flows/TlsCredentials.java index 657d1036d..95747ffc8 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).getHostText()); + return InetAddresses.forString(HostAndPort.fromString(asciiAddr).getHost()); } catch (IllegalArgumentException e) { return null; } diff --git a/java/google/registry/model/SchemaVersion.java b/java/google/registry/model/SchemaVersion.java index d611ffebb..0d90115a4 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(assignableFrom(Enum.class), assignableFrom(ImmutableObject.class))) + .filter(or(subtypeOf(Enum.class), subtypeOf(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 1f4731d83..21a84330a 100644 --- a/java/google/registry/model/server/Lock.java +++ b/java/google/registry/model/server/Lock.java @@ -193,7 +193,8 @@ public class Lock extends ImmutableObject { TimeUnit.MILLISECONDS, true); } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/java/google/registry/request/Router.java b/java/google/registry/request/Router.java index 0349c3d7c..d21df9d29 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.propagateIfPossible(e.getCause()); + Throwables.throwIfUnchecked(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 1c7ea6a41..cddb08aca 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.propagateIfInstanceOf; +import static com.google.common.base.Throwables.throwIfInstanceOf; 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) { - propagateIfInstanceOf(e.getCause(), GeneralSecurityException.class); + throwIfInstanceOf(e.getCause(), GeneralSecurityException.class); throw e; } } @@ -134,7 +134,7 @@ public final class TmchCertificateAuthority { try { return CRL_CACHE.get(); } catch (RuntimeException e) { - propagateIfInstanceOf(e.getCause(), GeneralSecurityException.class); + throwIfInstanceOf(e.getCause(), GeneralSecurityException.class); throw e; } } diff --git a/java/google/registry/tmch/TmchXmlSignature.java b/java/google/registry/tmch/TmchXmlSignature.java index e50218a00..55112c549 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.collect.ImmutableList; @@ -96,7 +96,7 @@ public final class TmchXmlSignature { isValid = signature.validate(context); } catch (XMLSignatureException e) { Throwable cause = getRootCause(e); - propagateIfInstanceOf(cause, GeneralSecurityException.class); + throwIfInstanceOf(cause, GeneralSecurityException.class); throw e; } if (!isValid) { diff --git a/java/google/registry/tools/AppEngineConnection.java b/java/google/registry/tools/AppEngineConnection.java index 6b4adde3c..01b29df36 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.getHostText().equals("localhost"); + return server.getHost().equals("localhost"); } private String getUserId() { diff --git a/java/google/registry/tools/RegistryCli.java b/java/google/registry/tools/RegistryCli.java index 392a503f8..7cc7c4330 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().getHostText(), connection.getServer().getPort()); + options.server(connection.getServer().getHost(), 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 2c0cbfeb6..1e4bdda45 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 50fec54f3..feb2d7654 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 77c5c9aef..54860e7b0 100644 --- a/javatests/google/registry/server/ServletWrapperDelegatorServlet.java +++ b/javatests/google/registry/server/ServletWrapperDelegatorServlet.java @@ -62,9 +62,10 @@ 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()); + Throwables.throwIfInstanceOf(e.getCause(), ServletException.class); + Throwables.throwIfInstanceOf(e.getCause(), IOException.class); + Throwables.throwIfUnchecked(e.getCause()); + throw new RuntimeException(e.getCause()); } } diff --git a/javatests/google/registry/server/TestServer.java b/javatests/google/registry/server/TestServer.java index a5e64ea51..4966e5ac5 100644 --- a/javatests/google/registry/server/TestServer.java +++ b/javatests/google/registry/server/TestServer.java @@ -91,7 +91,8 @@ public final class TestServer { try { server.start(); } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } UrlChecker.waitUntilAvailable(getUrl("/healthz"), STARTUP_TIMEOUT_MS); } @@ -129,7 +130,8 @@ public final class TestServer { } }, SHUTDOWN_TIMEOUT_MS, TimeUnit.MILLISECONDS, true); } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } @@ -166,20 +168,20 @@ public final class TestServer { private static Connector createConnector(HostAndPort address) { SocketConnector connector = new SocketConnector(); - connector.setHost(address.getHostText()); + connector.setHost(address.getHost()); 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.getHostText().equals("::") || address.getHostText().equals("0.0.0.0")) { + if (address.getHost().equals("::") || address.getHost().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.getHostText()) + ? HostAndPort.fromHost(address.getHost()) : address; } } diff --git a/javatests/google/registry/server/UrlChecker.java b/javatests/google/registry/server/UrlChecker.java index 8efcfed3e..09786ca74 100644 --- a/javatests/google/registry/server/UrlChecker.java +++ b/javatests/google/registry/server/UrlChecker.java @@ -45,7 +45,8 @@ final class UrlChecker { } }, timeoutMs, TimeUnit.MILLISECONDS, true); } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/javatests/google/registry/tools/params/HostAndPortParameterTest.java b/javatests/google/registry/tools/params/HostAndPortParameterTest.java index 82de7ae6c..90610bf1f 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").getHostText()).isEqualTo("foo.bar"); + assertThat(instance.convert("foo.bar").getHost()).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").getHostText()).isEqualTo("foo.bar"); + assertThat(instance.convert("foo.bar:1234").getHost()).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]").getHostText()).isEqualTo("feed:a:bee"); + assertThat(instance.convert("[feed:a:bee]").getHost()).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").getHostText()).isEqualTo("feed:a:bee"); + assertThat(instance.convert("[feed:a:bee]:1234").getHost()).isEqualTo("feed:a:bee"); assertThat(instance.convert("[feed:a:bee]:1234").getPortOrDefault(31337)).isEqualTo(1234); } }