Skip to content
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

Avoid NPE in ConnectPlan #8514

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
yschimke committed Aug 17, 2024
commit a931bd092523274d11d945f34752de7320c3c2f4
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 177,7 @@ class ConnectPlan(
// that happens, then we will have buffered bytes that are needed by the SSLSocket!
// This check is imperfect: it doesn't tell us whether a handshake will succeed, just
// that it will almost certainly fail because the proxy has sent unexpected data.
if (source?.buffer?.exhausted() == false || sink?.buffer?.exhausted() == false) {
if (!source.buffer.exhausted() || !sink.buffer.exhausted()) {
throw IOException("TLS tunnel buffered too many bytes!")
}

Expand Down Expand Up @@ -219,7 219,7 @@ class ConnectPlan(
rawSocket = rawSocket,
socket = socket!!,
handshake = handshake,
protocol = protocol,
protocol = protocol!!,
source = source,
sink = sink,
pingIntervalMillis = pingIntervalMillis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 73,14 @@ class RealConnection(
val connectionPool: RealConnectionPool,
override val route: Route,
/** The low-level TCP socket. */
private var rawSocket: Socket,
private val rawSocket: Socket,
/**
* The application layer socket. Either an [SSLSocket] layered over [rawSocket], or [rawSocket]
* itself if this connection does not use SSL.
*/
private var socket: Socket,
private var handshake: Handshake?,
private var protocol: Protocol?,
private val socket: Socket,
private val handshake: Handshake?,
private val protocol: Protocol,
private val source: BufferedSource,
private val sink: BufferedSink,
private val pingIntervalMillis: Int,
Expand Down Expand Up @@ -168,9 168,6 @@ class RealConnection(

@Throws(IOException::class)
private fun startHttp2() {
val socket = this.socket
val source = this.source
val sink = this.sink
socket.soTimeout = 0 // HTTP/2 connection timeouts are set per-stream.
val flowControlListener = connectionListener as? FlowControlListener ?: FlowControlListener.None
val http2Connection =
Expand Down Expand Up @@ -259,7 256,7 @@ class RealConnection(
}

// We have a host mismatch. But if the certificate matches, we're still good.
return !noCoalescedConnections && handshake != null && certificateSupportHost(url, handshake!!)
return !noCoalescedConnections && handshake != null && certificateSupportHost(url, handshake)
}

private fun certificateSupportHost(
Expand Down Expand Up @@ -441,7 438,7 @@ class RealConnection(
}
}

override fun protocol(): Protocol = protocol!!
override fun protocol(): Protocol = protocol

override fun toString(): String {
return "Connection{${route.address.url.host}:${route.address.url.port},"
Expand Down Expand Up @@ -469,7 466,7 @@ class RealConnection(
rawSocket = Socket(),
socket = socket,
handshake = null,
protocol = null,
protocol = Protocol.HTTP_2,
source =
object : Source {
override fun close() = Unit
Expand Down