-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Avoid NPEs in JavaNetAuthenticator #9100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,17 +53,21 @@ class JavaNetAuthenticator( | |
| val dns = route?.address?.dns ?: defaultDns | ||
| val auth = | ||
| if (proxyAuthorization) { | ||
| val proxyAddress = proxy.address() as InetSocketAddress | ||
| Authenticator.requestPasswordAuthentication( | ||
| proxyAddress.hostName, | ||
| proxy.connectToInetAddress(url, dns), | ||
| proxyAddress.port, | ||
| url.scheme, | ||
| challenge.realm, | ||
| challenge.scheme, | ||
| url.toUrl(), | ||
| Authenticator.RequestorType.PROXY, | ||
| ) | ||
| if (proxy.type() == Proxy.Type.HTTP) { | ||
| val proxyAddress = proxy.address() as InetSocketAddress | ||
| Authenticator.requestPasswordAuthentication( | ||
| proxyAddress.hostName, | ||
| proxy.connectToInetAddress(url, dns), | ||
| proxyAddress.port, | ||
| url.scheme, | ||
| challenge.realm, | ||
| challenge.scheme, | ||
| url.toUrl(), | ||
| Authenticator.RequestorType.PROXY, | ||
| ) | ||
| } else { | ||
| null | ||
| } | ||
| } else { | ||
| Authenticator.requestPasswordAuthentication( | ||
| url.host, | ||
|
|
@@ -102,6 +106,13 @@ class JavaNetAuthenticator( | |
| ): InetAddress = | ||
| when (type()) { | ||
| Proxy.Type.DIRECT -> dns.lookup(url.host).first() | ||
| else -> (address() as InetSocketAddress).address | ||
| else -> { | ||
| val socketAddress = address() as InetSocketAddress | ||
| if (socketAddress.isUnresolved) { | ||
| dns.lookup(socketAddress.hostString).first() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this resolving the DNS address? I don’t think we guarantee that we’ll use this same resolved address later when we connect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhh, I see from your stack trace. Hmmmmm..... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let’s just change this function to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that’s what this should do.
|
||
| } else { | ||
| socketAddress.address | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.