Skip to content

Don't crash route selection when the system proxy selector throws#9478

Merged
swankjesse merged 1 commit into
square:masterfrom
SAY-5:fix-proxyselector-iae
Jun 9, 2026
Merged

Don't crash route selection when the system proxy selector throws#9478
swankjesse merged 1 commit into
square:masterfrom
SAY-5:fix-proxyselector-iae

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #9469.

When no explicit proxy is configured, RouteSelector calls address.proxySelector.select(uri) and only handles a null/empty return. On Android the platform DefaultProxySelector can itself throw IllegalArgumentException: port out of range:-1 when a system proxy is configured (via APN/MDM) with an unset port. That exception propagates out of resetNextProxy and crashes the call on the dispatcher thread, even though OkHttp already rejects out-of-range proxy ports elsewhere.

This treats a throwing ProxySelector.select() the same as a null/empty result and falls back to a direct connection, which matches how the surrounding code already handles "no usable proxy". Added a RouteSelectorTest case that fails on the current code and passes with the fix.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>

@swankjesse swankjesse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great test.

@swankjesse swankjesse merged commit 668794b into square:master Jun 9, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IllegalArgumentException: port out of range:-1 from DefaultProxySelector.select() propagates uncaught through RouteSelector.resetNextProxy

2 participants