Skip to content

Commit a2db15c

Browse files
committed
core: Validate load-balancing policy name early in ManagedChannelBuilder (#12695)
1 parent c43ded4 commit a2db15c

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

api/src/main/java/io/grpc/ManagedChannelBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.grpc;
1818

1919
import com.google.common.base.Preconditions;
20+
import java.nio.channels.Channel;
2021
import java.util.List;
2122
import java.util.Map;
2223
import java.util.concurrent.Executor;
@@ -269,7 +270,7 @@ public T useTransportSecurity() {
269270

270271
/**
271272
* Sets the default load-balancing policy that will be used if the service config doesn't specify
272-
* one. If not set, the default will be the "pick_first" policy.
273+
* one. If not set, the default will be the "pick_first" policy.
273274
*
274275
* <p>Policy implementations are looked up in the
275276
* {@link LoadBalancerRegistry#getDefaultRegistry default LoadBalancerRegistry}.
@@ -283,9 +284,8 @@ public T useTransportSecurity() {
283284
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
284285
public T defaultLoadBalancingPolicy(String policy) {
285286
Preconditions.checkArgument(
286-
LoadBalancerRegistry.getDefaultRegistry().getProvider(policy) != null,
287-
"invalid load balancing policy %s", policy
288-
);
287+
LoadBalancerRegistry.getDefaultRegistry().getProvider(policy) != null,
288+
"invalid load balancing policy %s", policy);
289289
throw new UnsupportedOperationException();
290290
}
291291

core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ public static ManagedChannelBuilder<?> forTarget(String target) {
213213
private boolean recordRetryMetrics = true;
214214
private boolean tracingEnabled = true;
215215
List<MetricSink> metricSinks = new ArrayList<>();
216-
217216
/**
218217
* An interface for Transport implementors to provide the {@link ClientTransportFactory}
219218
* appropriate for the channel.
220219
*/
220+
221221
public interface ClientTransportFactoryBuilder {
222222
ClientTransportFactory buildClientTransportFactory();
223223
}
@@ -448,12 +448,9 @@ public ManagedChannelImplBuilder defaultLoadBalancingPolicy(String policy) {
448448
"directServerAddress is set (%s), which forbids the use of load-balancing policy",
449449
directServerAddress);
450450
Preconditions.checkArgument(policy != null, "policy cannot be null");
451-
452-
Preconditions.checkArgument(
453-
LoadBalancerRegistry.getDefaultRegistry().getProvider(policy) != null,
454-
"invalid load-balancing policy %s", policy
455-
);
456-
451+
Preconditions.checkArgument( // (4 spaces)
452+
LoadBalancerRegistry.getDefaultRegistry().getProvider(policy) != null, // (8 spaces)
453+
"invalid load-balancing policy %s", policy); // (8 spaces)
457454
this.defaultLbPolicy = policy;
458455
return this;
459456
}

0 commit comments

Comments
 (0)