Skip to content

Commit b6066e0

Browse files
committed
core: handle empty proxy selector result
1 parent f4125c5 commit b6066e0

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ private ProxiedSocketAddress detectProxy(InetSocketAddress targetAddr) throws IO
207207
}
208208

209209
List<Proxy> proxies = proxySelector.select(uri);
210+
if (proxies == null || proxies.isEmpty()) {
211+
log.log(Level.FINE, "No proxies returned, proceeding without proxy");
212+
return null;
213+
}
210214
if (proxies.size() > 1) {
211215
log.warning("More than 1 proxy detected, gRPC will select the first one");
212216
}

core/src/test/java/io/grpc/internal/ProxyDetectorImplTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.net.ProxySelector;
4141
import java.net.SocketAddress;
4242
import java.net.URI;
43+
import java.util.Collections;
4344
import org.junit.Before;
4445
import org.junit.Rule;
4546
import org.junit.Test;
@@ -191,4 +192,11 @@ public ProxySelector get() {
191192
authenticator);
192193
assertNull(proxyDetector.proxyFor(destination));
193194
}
195+
196+
@Test
197+
public void returnNullWhenProxySelectorReturnsEmptyList() throws Exception {
198+
when(proxySelector.select(any(URI.class))).thenReturn(Collections.<Proxy>emptyList());
199+
200+
assertNull(proxyDetector.proxyFor(destination));
201+
}
194202
}

0 commit comments

Comments
 (0)