Skip to content

Commit da523ca

Browse files
fix: real unmodifiable list (#8724)
1 parent 33854ec commit da523ca

File tree

1 file changed

+5
-4
lines changed
  • okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal

1 file changed

+5
-4
lines changed

okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/-UtilJvm.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import java.net.ServerSocket
2424
import java.net.Socket
2525
import java.net.SocketTimeoutException
2626
import java.nio.charset.Charset
27+
import java.util.Collections
2728
import java.util.Locale
2829
import java.util.TimeZone
2930
import java.util.concurrent.ThreadFactory
@@ -233,17 +234,17 @@ internal inline fun threadName(
233234
}
234235

235236
/** Returns the Content-Length as reported by the response headers. */
236-
internal fun Response.headersContentLength(): Long = headers["Content-Length"]?.toLongOrDefault(-1L) ?: -1L
237+
internal fun Response.headersContentLength(): Long = headers["Content-Length"]?.toLongOrNull() ?: -1L
237238

238239
/** Returns an immutable copy of this. */
239-
internal inline fun <reified T> List<T>.toImmutableList(): List<T> = toTypedArray().asList()
240+
internal inline fun <reified T> List<T>.toImmutableList(): List<T> = Collections.unmodifiableList(toTypedArray().asList())
240241

241242
/** Returns an immutable list containing [elements]. */
242243
@SafeVarargs
243-
internal fun <T> immutableListOf(vararg elements: T): List<T> = elements.asList()
244+
internal fun <T> immutableListOf(vararg elements: T): List<T> = Collections.unmodifiableList(elements.asList())
244245

245246
/** Returns an immutable list from copy of this. */
246-
internal fun <T> Array<out T>?.toImmutableList(): List<T> = this?.copyOf()?.asList() ?: emptyList()
247+
internal fun <T> Array<out T>?.toImmutableList(): List<T> = this?.let { Collections.unmodifiableList(it.copyOf().asList()) } ?: emptyList()
247248

248249
/** Closes this, ignoring any checked exceptions. */
249250
internal fun Socket.closeQuietly() {

0 commit comments

Comments
 (0)