From 829be86223c8ac92c8eb0396dce10c2b915f54c8 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Tue, 7 Jun 2016 21:58:46 -0400 Subject: [PATCH] Use a default resolver with bootstrap.resolver(null). Motivation: `Bootstrap` has a notion of a default resolver group, but it's hidden from the public. To allow callers to reset a `Bootstrap` instance's resolver group, we could either make `DEFAULT_RESOLVER` public, or we could allow callers to pass `null` as an argument to `Bootstrap#resolver(AddressResolverGroup)`. This pull request does the latter. Modifications: - Allow `Bootstrap#resolver(AddressResolverGroup)` to accept `null` as an argument Result: Callers may pass `null` to `Bootstrap#resolver(AddressResolverGroup)` to cause the `Bootstrap` instance to use its default resolver group. --- .../src/main/java/io/netty/bootstrap/Bootstrap.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/transport/src/main/java/io/netty/bootstrap/Bootstrap.java b/transport/src/main/java/io/netty/bootstrap/Bootstrap.java index ba93abe81e..fa52dea270 100644 --- a/transport/src/main/java/io/netty/bootstrap/Bootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/Bootstrap.java @@ -70,13 +70,15 @@ public class Bootstrap extends AbstractBootstrap { /** * Sets the {@link NameResolver} which will resolve the address of the unresolved named address. + * + * @param resolver the {@link NameResolver} for this {@code Bootstrap}; may be {@code null}, in which case a default + * resolver will be used + * + * @see io.netty.resolver.DefaultAddressResolverGroup */ @SuppressWarnings("unchecked") public Bootstrap resolver(AddressResolverGroup resolver) { - if (resolver == null) { - throw new NullPointerException("resolver"); - } - this.resolver = (AddressResolverGroup) resolver; + this.resolver = (AddressResolverGroup) (resolver == null ? DEFAULT_RESOLVER : resolver); return this; }