diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000000..0067d4488ef2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,2 @@ +[*.kt] +indent_size = 2 diff --git a/build.gradle b/build.gradle index 6d9974354f02..9e8df402ea93 100644 --- a/build.gradle +++ b/build.gradle @@ -15,10 +15,10 @@ buildscript { 'jnrUnixsocket': '0.28', 'jsoup': '1.13.1', 'junit': '4.13', - 'kotlin': '1.3.72', + 'kotlin': '1.4.0', 'moshi': '1.9.2', - 'okio': '2.7.0', - 'ktlint': '0.36.0', + 'okio': '2.8.0', + 'ktlint': '0.38.0', 'picocli': '4.2.0', 'openjsse': '1.1.0' ] @@ -47,11 +47,9 @@ buildscript { ] dependencies { - classpath 'net.ltgt.gradle:gradle-errorprone-plugin:1.1.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0" classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1" - classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.27.1' - classpath 'com.android.tools.build:gradle:3.6.2' + classpath "com.android.tools.build:gradle:4.0.1" } repositories { @@ -62,9 +60,11 @@ buildscript { } plugins { - id 'ru.vyarus.animalsniffer' version '1.5.0' - id 'com.github.johnrengelman.shadow' version '5.2.0' - id 'me.champeau.gradle.japicmp' version '0.2.9' + id "ru.vyarus.animalsniffer" version "1.5.0" + id "com.github.johnrengelman.shadow" version "5.2.0" + id "me.champeau.gradle.japicmp" version "0.2.9" + id "com.diffplug.spotless" version "5.1.2" + id "net.ltgt.errorprone" version "1.2.1" } /** Returns the artifact ID for the project, or null if it is not published. */ @@ -112,14 +112,12 @@ subprojects { project -> if (project.name == 'android-test') return if (project.name == 'okhttp-bom') return + apply plugin: "org.jetbrains.kotlin.jvm" apply plugin: 'java' apply plugin: 'java-library' - apply plugin: 'org.jetbrains.kotlin.platform.jvm' apply plugin: 'checkstyle' apply plugin: 'ru.vyarus.animalsniffer' - apply plugin: 'net.ltgt.errorprone' apply plugin: 'org.jetbrains.dokka' - apply plugin: 'com.diffplug.gradle.spotless' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 @@ -152,13 +150,6 @@ subprojects { project -> signature 'org.codehaus.mojo.signature:java18:1.0@signature' } - spotless { - kotlin { - target "**/*.kt" - ktlint(versions.ktlint).userData(['indent_size': '2', 'continuation_indent_size': '2']) - } - } - tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { kotlinOptions { jvmTarget = "1.8" @@ -205,20 +196,9 @@ subprojects { project -> } } - dependencies { - //noinspection GradleDynamicVersion - errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1' - errorprone 'com.google.errorprone:error_prone_core:2.3.4' - } tasks.withType(JavaCompile).configureEach { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 - - options.errorprone { - check("MissingFail", CheckSeverity.ERROR) - check("MissingOverride", CheckSeverity.ERROR) - enabled = JavaVersion.current() < JavaVersion.VERSION_12 - } } dokka { diff --git a/okcurl/src/main/kotlin/okhttp3/curl/Main.kt b/okcurl/src/main/kotlin/okhttp3/curl/Main.kt index 17dd983323ed..1c6d9d9df4f4 100644 --- a/okcurl/src/main/kotlin/okhttp3/curl/Main.kt +++ b/okcurl/src/main/kotlin/okhttp3/curl/Main.kt @@ -168,11 +168,7 @@ class Main : Runnable { builder.hostnameVerifier(createInsecureHostnameVerifier()) } if (verbose) { - val logger = object : HttpLoggingInterceptor.Logger { - override fun log(message: String) { - println(message) - } - } + val logger = HttpLoggingInterceptor.Logger(::println) builder.eventListenerFactory(LoggingEventListener.Factory(logger)) } return builder.build() diff --git a/okhttp-logging-interceptor/src/main/kotlin/okhttp3/logging/HttpLoggingInterceptor.kt b/okhttp-logging-interceptor/src/main/kotlin/okhttp3/logging/HttpLoggingInterceptor.kt index 0133309c669e..5b8537eb0dcb 100644 --- a/okhttp-logging-interceptor/src/main/kotlin/okhttp3/logging/HttpLoggingInterceptor.kt +++ b/okhttp-logging-interceptor/src/main/kotlin/okhttp3/logging/HttpLoggingInterceptor.kt @@ -104,7 +104,7 @@ class HttpLoggingInterceptor @JvmOverloads constructor( BODY } - interface Logger { + fun interface Logger { fun log(message: String) companion object { diff --git a/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.java b/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.java index 105dd5c4472f..2cb920a07675 100644 --- a/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.java +++ b/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.java @@ -107,7 +107,7 @@ private void setLevel(Level level) { try { applicationInterceptor.setLevel(null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } } diff --git a/okhttp-sse/src/main/kotlin/okhttp3/sse/EventSource.kt b/okhttp-sse/src/main/kotlin/okhttp3/sse/EventSource.kt index 38174e1ab042..ec280d5b5df9 100644 --- a/okhttp-sse/src/main/kotlin/okhttp3/sse/EventSource.kt +++ b/okhttp-sse/src/main/kotlin/okhttp3/sse/EventSource.kt @@ -27,7 +27,7 @@ interface EventSource { */ fun cancel() - interface Factory { + fun interface Factory { /** * Creates a new event source and immediately returns it. Creating an event source initiates an * asynchronous process to connect the socket. Once that succeeds or fails, `listener` will be diff --git a/okhttp-sse/src/main/kotlin/okhttp3/sse/EventSources.kt b/okhttp-sse/src/main/kotlin/okhttp3/sse/EventSources.kt index 8059ee709d7c..fcb6a555030e 100644 --- a/okhttp-sse/src/main/kotlin/okhttp3/sse/EventSources.kt +++ b/okhttp-sse/src/main/kotlin/okhttp3/sse/EventSources.kt @@ -16,25 +16,22 @@ package okhttp3.sse import okhttp3.OkHttpClient -import okhttp3.Request import okhttp3.Response import okhttp3.internal.sse.RealEventSource object EventSources { @JvmStatic fun createFactory(client: OkHttpClient): EventSource.Factory { - return object : EventSource.Factory { - override fun newEventSource(request: Request, listener: EventSourceListener): EventSource { - val actualRequest = - if (request.header("Accept") == null) { - request.newBuilder().addHeader("Accept", "text/event-stream").build() - } else { - request - } - - return RealEventSource(actualRequest, listener).apply { - connect(client) + return EventSource.Factory { request, listener -> + val actualRequest = + if (request.header("Accept") == null) { + request.newBuilder().addHeader("Accept", "text/event-stream").build() + } else { + request } + + RealEventSource(actualRequest, listener).apply { + connect(client) } } } diff --git a/okhttp-testing-support/src/main/kotlin/okhttp3/OkHttpClientTestRule.kt b/okhttp-testing-support/src/main/kotlin/okhttp3/OkHttpClientTestRule.kt index 8382129393b9..e0174acb4caa 100644 --- a/okhttp-testing-support/src/main/kotlin/okhttp3/OkHttpClientTestRule.kt +++ b/okhttp-testing-support/src/main/kotlin/okhttp3/OkHttpClientTestRule.kt @@ -92,14 +92,11 @@ class OkHttpClientTestRule : TestRule { Logger.getLogger("javax.net.ssl").fn() } - fun wrap(eventListener: EventListener) = object : EventListener.Factory { - override fun create(call: Call) = ClientRuleEventListener(eventListener) { addEvent(it) } - } + fun wrap(eventListener: EventListener) = + EventListener.Factory { ClientRuleEventListener(eventListener, ::addEvent) } - fun wrap(eventListenerFactory: EventListener.Factory) = object : EventListener.Factory { - override fun create(call: Call) = - ClientRuleEventListener(eventListenerFactory.create(call)) { addEvent(it) } - } + fun wrap(eventListenerFactory: EventListener.Factory) = + EventListener.Factory { call -> ClientRuleEventListener(eventListenerFactory.create(call), ::addEvent) } /** * Returns an OkHttpClient for tests to use as a starting point. @@ -115,9 +112,8 @@ class OkHttpClientTestRule : TestRule { if (client == null) { client = OkHttpClient.Builder() .dns(SINGLE_INET_ADDRESS_DNS) // Prevent unexpected fallback addresses. - .eventListenerFactory(object : EventListener.Factory { - override fun create(call: Call) = ClientRuleEventListener { addEvent(it) } - }) + .eventListenerFactory( + EventListener.Factory { ClientRuleEventListener(logger = ::addEvent) }) .build() testClient = client } diff --git a/okhttp/build.gradle b/okhttp/build.gradle index 6804ce950794..df42f42810a2 100644 --- a/okhttp/build.gradle +++ b/okhttp/build.gradle @@ -108,6 +108,8 @@ task japicmp(type: me.champeau.gradle.japicmp.JapicmpTask, dependsOn: 'jar') { 'okhttp3.OkHttpClient#socketFactory()', 'okhttp3.OkHttpClient#sslSocketFactory()', 'okhttp3.OkHttpClient#writeTimeoutMillis()', + 'okhttp3.OkHttpClient#writeTimeoutMillis()', + 'okhttp3.Request$Builder#delete()', ] } check.dependsOn(japicmp) diff --git a/okhttp/src/main/kotlin/okhttp3/Authenticator.kt b/okhttp/src/main/kotlin/okhttp3/Authenticator.kt index 4cb89fb0c9b8..0d6872edc6b6 100644 --- a/okhttp/src/main/kotlin/okhttp3/Authenticator.kt +++ b/okhttp/src/main/kotlin/okhttp3/Authenticator.kt @@ -112,7 +112,7 @@ import okhttp3.internal.authenticator.JavaNetAuthenticator * * [1]: https://tools.ietf.org/html/rfc2817 */ -interface Authenticator { +fun interface Authenticator { /** * Returns a request that includes a credential to satisfy an authentication challenge in * [response]. Returns null if the challenge cannot be satisfied. diff --git a/okhttp/src/main/kotlin/okhttp3/Cache.kt b/okhttp/src/main/kotlin/okhttp3/Cache.kt index 491c8dac9911..82baf682d63d 100644 --- a/okhttp/src/main/kotlin/okhttp3/Cache.kt +++ b/okhttp/src/main/kotlin/okhttp3/Cache.kt @@ -386,12 +386,12 @@ class Cache internal constructor( @Synchronized fun requestCount(): Int = requestCount - private inner class RealCacheRequest internal constructor( + private inner class RealCacheRequest( private val editor: DiskLruCache.Editor ) : CacheRequest { private val cacheOut: Sink = editor.newSink(ENTRY_BODY) private val body: Sink - internal var done = false + var done = false init { this.body = object : ForwardingSink(cacheOut) { @@ -489,8 +489,7 @@ class Cache internal constructor( * each on their own line. A length of -1 is used to encode a null array. The last line is * optional. If present, it contains the TLS version. */ - @Throws(IOException::class) - internal constructor(rawSource: Source) { + @Throws(IOException::class) constructor(rawSource: Source) { try { val source = rawSource.buffer() url = source.readUtf8LineStrict() @@ -542,7 +541,7 @@ class Cache internal constructor( } } - internal constructor(response: Response) { + constructor(response: Response) { this.url = response.request.url.toString() this.varyHeaders = response.varyHeaders() this.requestMethod = response.request.method @@ -665,8 +664,8 @@ class Cache internal constructor( } } - private class CacheResponseBody internal constructor( - internal val snapshot: DiskLruCache.Snapshot, + private class CacheResponseBody( + val snapshot: DiskLruCache.Snapshot, private val contentType: String?, private val contentLength: String? ) : ResponseBody() { diff --git a/okhttp/src/main/kotlin/okhttp3/Call.kt b/okhttp/src/main/kotlin/okhttp3/Call.kt index 6df8da0e9cbd..66677f62726c 100644 --- a/okhttp/src/main/kotlin/okhttp3/Call.kt +++ b/okhttp/src/main/kotlin/okhttp3/Call.kt @@ -93,7 +93,7 @@ interface Call : Cloneable { */ public override fun clone(): Call - interface Factory { + fun interface Factory { fun newCall(request: Request): Call } } diff --git a/okhttp/src/main/kotlin/okhttp3/EventListener.kt b/okhttp/src/main/kotlin/okhttp3/EventListener.kt index ea0b6eb45071..b742d1d9b650 100644 --- a/okhttp/src/main/kotlin/okhttp3/EventListener.kt +++ b/okhttp/src/main/kotlin/okhttp3/EventListener.kt @@ -457,7 +457,7 @@ abstract class EventListener { open fun cacheConditionalHit(call: Call, cachedResponse: Response) { } - interface Factory { + fun interface Factory { /** * Creates an instance of the [EventListener] for a particular [Call]. The returned * [EventListener] instance will be used during the lifecycle of [call]. diff --git a/okhttp/src/main/kotlin/okhttp3/Handshake.kt b/okhttp/src/main/kotlin/okhttp3/Handshake.kt index 4bc98acc1b69..e030b1be4b8f 100644 --- a/okhttp/src/main/kotlin/okhttp3/Handshake.kt +++ b/okhttp/src/main/kotlin/okhttp3/Handshake.kt @@ -52,7 +52,7 @@ class Handshake internal constructor( try { peerCertificatesFn() } catch (spue: SSLPeerUnverifiedException) { - listOf() + listOf() } } @@ -160,7 +160,7 @@ class Handshake internal constructor( val peerCertificatesCopy = try { peerCertificates.toImmutableList() } catch (_: SSLPeerUnverifiedException) { - listOf() + listOf() } return Handshake(tlsVersion, cipherSuite, diff --git a/okhttp/src/main/kotlin/okhttp3/Interceptor.kt b/okhttp/src/main/kotlin/okhttp3/Interceptor.kt index 2452cff367f7..8da5b803d468 100644 --- a/okhttp/src/main/kotlin/okhttp3/Interceptor.kt +++ b/okhttp/src/main/kotlin/okhttp3/Interceptor.kt @@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit * responses coming back in. Typically interceptors add, remove, or transform headers on the request * or response. */ -interface Interceptor { +fun interface Interceptor { @Throws(IOException::class) fun intercept(chain: Chain): Response @@ -39,9 +39,7 @@ interface Interceptor { * ``` */ inline operator fun invoke(crossinline block: (chain: Chain) -> Response): Interceptor = - object : Interceptor { - override fun intercept(chain: Chain) = block(chain) - } + Interceptor { block(it) } } interface Chain { diff --git a/okhttp/src/main/kotlin/okhttp3/WebSocket.kt b/okhttp/src/main/kotlin/okhttp3/WebSocket.kt index 01d2faa245d0..ac731e62e1b1 100644 --- a/okhttp/src/main/kotlin/okhttp3/WebSocket.kt +++ b/okhttp/src/main/kotlin/okhttp3/WebSocket.kt @@ -109,7 +109,7 @@ interface WebSocket { */ fun cancel() - interface Factory { + fun interface Factory { /** * Creates a new web socket and immediately returns it. Creating a web socket initiates an * asynchronous process to connect the socket. Once that succeeds or fails, `listener` will be diff --git a/okhttp/src/main/kotlin/okhttp3/internal/Util.kt b/okhttp/src/main/kotlin/okhttp3/internal/Util.kt index bb5a569ae749..55a8b7b2c76c 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/Util.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/Util.kt @@ -29,7 +29,6 @@ import java.nio.charset.Charset import java.nio.charset.StandardCharsets.UTF_16BE import java.nio.charset.StandardCharsets.UTF_16LE import java.nio.charset.StandardCharsets.UTF_8 -import java.util.Arrays import java.util.Collections import java.util.Comparator import java.util.LinkedHashMap @@ -300,9 +299,7 @@ fun HttpUrl.canReuseConnectionFor(other: HttpUrl): Boolean = host == other.host port == other.port && scheme == other.scheme -fun EventListener.asFactory() = object : EventListener.Factory { - override fun create(call: Call): EventListener = this@asFactory -} +fun EventListener.asFactory() = EventListener.Factory { this } infix fun Byte.and(mask: Int): Int = toInt() and mask infix fun Short.and(mask: Int): Int = toInt() and mask @@ -378,18 +375,18 @@ fun Socket.peerName(): String { * @param source the source used to read bytes from the socket. */ fun Socket.isHealthy(source: BufferedSource): Boolean { - try { + return try { val readTimeout = soTimeout try { soTimeout = 1 - return !source.exhausted() + !source.exhausted() } finally { soTimeout = readTimeout } } catch (_: SocketTimeoutException) { - return true // Read timed out; socket is good. + true // Read timed out; socket is good. } catch (_: IOException) { - return false // Couldn't read; socket is closed. + false // Couldn't read; socket is closed. } } @@ -473,7 +470,7 @@ fun List.toImmutableList(): List { /** Returns an immutable list containing [elements]. */ @SafeVarargs fun immutableListOf(vararg elements: T): List { - return Collections.unmodifiableList(Arrays.asList(*elements.clone())) + return Collections.unmodifiableList(listOf(*elements.clone())) } /** Returns an immutable copy of this. */ diff --git a/okhttp/src/main/kotlin/okhttp3/internal/connection/Exchange.kt b/okhttp/src/main/kotlin/okhttp3/internal/connection/Exchange.kt index fc44f72be339..ca93f27c4b4c 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/connection/Exchange.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/connection/Exchange.kt @@ -198,7 +198,7 @@ class Exchange( } /** A request body that fires events when it completes. */ - private inner class RequestBodySink internal constructor( + private inner class RequestBodySink( delegate: Sink, /** The exact number of bytes to be written, or -1L if that is unknown. */ private val contentLength: Long diff --git a/okhttp/src/main/kotlin/okhttp3/internal/http1/Http1ExchangeCodec.kt b/okhttp/src/main/kotlin/okhttp3/internal/http1/Http1ExchangeCodec.kt index 76f03597dac7..156085e14329 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/http1/Http1ExchangeCodec.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/http1/Http1ExchangeCodec.kt @@ -340,7 +340,7 @@ class Http1ExchangeCodec( * Closes the cache entry and makes the socket available for reuse. This should be invoked when * the end of the body has been reached. */ - internal fun responseBodyComplete() { + fun responseBodyComplete() { if (state == STATE_CLOSED) return if (state != STATE_READING_RESPONSE_BODY) throw IllegalStateException("state: $state") @@ -351,7 +351,7 @@ class Http1ExchangeCodec( } /** An HTTP body with a fixed length specified in advance. */ - private inner class FixedLengthSource internal constructor(private var bytesRemaining: Long) : + private inner class FixedLengthSource(private var bytesRemaining: Long) : AbstractSource() { init { @@ -394,7 +394,7 @@ class Http1ExchangeCodec( } /** An HTTP body with alternating chunk sizes and chunk bodies. */ - private inner class ChunkedSource internal constructor(private val url: HttpUrl) : + private inner class ChunkedSource(private val url: HttpUrl) : AbstractSource() { private var bytesRemainingInChunk = NO_CHUNK_YET private var hasMoreChunks = true diff --git a/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Connection.kt b/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Connection.kt index 80cd5875dc3a..3f5c0714174a 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Connection.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Connection.kt @@ -737,10 +737,10 @@ class Http2Connection internal constructor(builder: Builder) : Closeable { synchronized(writer) { synchronized(this@Http2Connection) { val previousPeerSettings = peerSettings - if (clearPrevious) { - newPeerSettings = settings + newPeerSettings = if (clearPrevious) { + settings } else { - newPeerSettings = Settings().apply { + Settings().apply { merge(previousPeerSettings) merge(settings) } diff --git a/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Reader.kt b/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Reader.kt index 8ad9428f0a8b..477ec3bd1260 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Reader.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Reader.kt @@ -75,7 +75,7 @@ class Http2Reader( } } else { // The server reads the CONNECTION_PREFACE byte string. - val connectionPreface = source.readByteString(Http2.CONNECTION_PREFACE.size.toLong()) + val connectionPreface = source.readByteString(CONNECTION_PREFACE.size.toLong()) if (logger.isLoggable(FINE)) logger.fine(format("<< CONNECTION ${connectionPreface.hex()}")) if (CONNECTION_PREFACE != connectionPreface) { throw IOException("Expected a connection header but was ${connectionPreface.utf8()}") diff --git a/okhttp/src/main/kotlin/okhttp3/internal/platform/BouncyCastlePlatform.kt b/okhttp/src/main/kotlin/okhttp3/internal/platform/BouncyCastlePlatform.kt index d53ebe46cf16..e0bcb5530450 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/platform/BouncyCastlePlatform.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/platform/BouncyCastlePlatform.kt @@ -48,7 +48,7 @@ class BouncyCastlePlatform private constructor() : Platform() { return trustManagers[0] as X509TrustManager } - public override fun trustManager(sslSocketFactory: SSLSocketFactory): X509TrustManager? = + override fun trustManager(sslSocketFactory: SSLSocketFactory): X509TrustManager? = throw UnsupportedOperationException( "clientBuilder.sslSocketFactory(SSLSocketFactory) not supported with BouncyCastle") diff --git a/okhttp/src/main/kotlin/okhttp3/internal/platform/Jdk8WithJettyBootPlatform.kt b/okhttp/src/main/kotlin/okhttp3/internal/platform/Jdk8WithJettyBootPlatform.kt index 8d59af4b0b11..e7ffc9437971 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/platform/Jdk8WithJettyBootPlatform.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/platform/Jdk8WithJettyBootPlatform.kt @@ -77,14 +77,14 @@ class Jdk8WithJettyBootPlatform( * Handle the methods of ALPN's ClientProvider and ServerProvider without a compile-time * dependency on those interfaces. */ - private class AlpnProvider internal constructor( + private class AlpnProvider( /** This peer's supported protocols. */ private val protocols: List ) : InvocationHandler { /** Set when remote peer notifies ALPN is unsupported. */ - internal var unsupported: Boolean = false + var unsupported: Boolean = false /** The protocol the server selected. */ - internal var selected: String? = null + var selected: String? = null @Throws(Throwable::class) override fun invoke(proxy: Any, method: Method, args: Array?): Any? { diff --git a/okhttp/src/main/kotlin/okhttp3/internal/platform/Jdk9Platform.kt b/okhttp/src/main/kotlin/okhttp3/internal/platform/Jdk9Platform.kt index fd4f0b56de1a..fd29f340a44e 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/platform/Jdk9Platform.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/platform/Jdk9Platform.kt @@ -53,7 +53,7 @@ open class Jdk9Platform : Platform() { } } - public override fun trustManager(sslSocketFactory: SSLSocketFactory): X509TrustManager? { + override fun trustManager(sslSocketFactory: SSLSocketFactory): X509TrustManager? { // Not supported due to access checks on JDK 9+: // java.lang.reflect.InaccessibleObjectException: Unable to make member of class // sun.security.ssl.SSLSocketFactoryImpl accessible: module java.base does not export diff --git a/okhttp/src/main/kotlin/okhttp3/internal/platform/OpenJSSEPlatform.kt b/okhttp/src/main/kotlin/okhttp3/internal/platform/OpenJSSEPlatform.kt index 15818d289e6a..040585cbe153 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/platform/OpenJSSEPlatform.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/platform/OpenJSSEPlatform.kt @@ -50,7 +50,7 @@ class OpenJSSEPlatform private constructor() : Platform() { return trustManagers[0] as X509TrustManager } - public override fun trustManager(sslSocketFactory: SSLSocketFactory): X509TrustManager? = + override fun trustManager(sslSocketFactory: SSLSocketFactory): X509TrustManager? = throw UnsupportedOperationException( "clientBuilder.sslSocketFactory(SSLSocketFactory) not supported with OpenJSSE") diff --git a/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt b/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt index 614fd818eb71..451f67e60ae7 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt @@ -203,8 +203,8 @@ class PublicSuffixDatabase { @Throws(IOException::class) private fun readTheList() { - var publicSuffixListBytes: ByteArray? = null - var publicSuffixExceptionListBytes: ByteArray? = null + var publicSuffixListBytes: ByteArray? + var publicSuffixExceptionListBytes: ByteArray? val resource = PublicSuffixDatabase::class.java.getResourceAsStream(PUBLIC_SUFFIX_RESOURCE) ?: return diff --git a/okhttp/src/main/kotlin/okhttp3/internal/tls/BasicCertificateChainCleaner.kt b/okhttp/src/main/kotlin/okhttp3/internal/tls/BasicCertificateChainCleaner.kt index 35d7f721fdf6..ee8a78414120 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/tls/BasicCertificateChainCleaner.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/tls/BasicCertificateChainCleaner.kt @@ -46,7 +46,7 @@ class BasicCertificateChainCleaner( */ @Throws(SSLPeerUnverifiedException::class) override fun clean(chain: List, hostname: String): List { - val queue: Deque = ArrayDeque(chain) + val queue: Deque = ArrayDeque(chain) val result = mutableListOf() result.add(queue.removeFirst()) var foundTrustedCertificate = false diff --git a/okhttp/src/main/kotlin/okhttp3/internal/ws/WebSocketExtensions.kt b/okhttp/src/main/kotlin/okhttp3/internal/ws/WebSocketExtensions.kt index 850e7abc7341..4e82c290f8dc 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/ws/WebSocketExtensions.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/ws/WebSocketExtensions.kt @@ -80,10 +80,10 @@ data class WebSocketExtensions( ) { fun noContextTakeover(clientOriginated: Boolean): Boolean { - if (clientOriginated) { - return clientNoContextTakeover // Client is deflating. + return if (clientOriginated) { + clientNoContextTakeover // Client is deflating. } else { - return serverNoContextTakeover // Server is deflating. + serverNoContextTakeover // Server is deflating. } } diff --git a/okhttp/src/main/kotlin/okhttp3/internal/ws/WebSocketReader.kt b/okhttp/src/main/kotlin/okhttp3/internal/ws/WebSocketReader.kt index 92b75fc63ca6..6d306cbcd9b4 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/ws/WebSocketReader.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/ws/WebSocketReader.kt @@ -133,11 +133,11 @@ class WebSocketReader( val reservedFlag1 = b0 and B0_FLAG_RSV1 != 0 when (opcode) { OPCODE_TEXT, OPCODE_BINARY -> { - if (reservedFlag1) { + readingCompressedMessage = if (reservedFlag1) { if (!perMessageDeflate) throw ProtocolException("Unexpected rsv1 flag") - readingCompressedMessage = true + true } else { - readingCompressedMessage = false + false } } else -> { diff --git a/okhttp/src/test/java/okhttp3/CipherSuiteTest.java b/okhttp/src/test/java/okhttp3/CipherSuiteTest.java index d70d7d4b17f4..cf3dd0c179cd 100644 --- a/okhttp/src/test/java/okhttp3/CipherSuiteTest.java +++ b/okhttp/src/test/java/okhttp3/CipherSuiteTest.java @@ -31,7 +31,7 @@ public class CipherSuiteTest { try { forJavaName(null); fail("Should have thrown"); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } } diff --git a/okhttp/src/test/java/okhttp3/CookieTest.java b/okhttp/src/test/java/okhttp3/CookieTest.java index bf2add65e3a9..e90343610746 100644 --- a/okhttp/src/test/java/okhttp3/CookieTest.java +++ b/okhttp/src/test/java/okhttp3/CookieTest.java @@ -427,7 +427,7 @@ public final class CookieTest { try { new Cookie.Builder().name(null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } try { new Cookie.Builder().name(" a "); @@ -440,7 +440,7 @@ public final class CookieTest { try { new Cookie.Builder().value(null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } try { new Cookie.Builder().value(" b "); @@ -485,7 +485,7 @@ public final class CookieTest { try { new Cookie.Builder().hostOnlyDomain(null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } try { new Cookie.Builder().hostOnlyDomain("a/b"); @@ -518,7 +518,7 @@ public final class CookieTest { try { new Cookie.Builder().path(null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } try { new Cookie.Builder().path("foo"); diff --git a/okhttp/src/test/java/okhttp3/HeadersTest.java b/okhttp/src/test/java/okhttp3/HeadersTest.java index 6ada63c49147..cbb86ae8c570 100644 --- a/okhttp/src/test/java/okhttp3/HeadersTest.java +++ b/okhttp/src/test/java/okhttp3/HeadersTest.java @@ -15,14 +15,12 @@ */ package okhttp3; -import java.io.IOException; import java.time.Instant; import java.util.Collections; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import kotlin.TypeCastException; import okhttp3.internal.Util; import okhttp3.internal.http.HttpHeaders; import okhttp3.internal.http2.Header; @@ -201,7 +199,7 @@ public final class HeadersTest { try { Headers.of(Collections.singletonMap("User-Agent", null)); fail(); - } catch (TypeCastException expected) { + } catch (NullPointerException expected) { } } @@ -831,7 +829,7 @@ public final class HeadersTest { .add("testDate", (Date) null) .build(); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } } @@ -850,7 +848,7 @@ public final class HeadersTest { .add("Test-Instant", (Instant) null) .build(); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } } @@ -870,7 +868,7 @@ public final class HeadersTest { .set("testDate", (Date) null) .build(); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } } @@ -890,7 +888,7 @@ public final class HeadersTest { .set("Test-Instant", (Instant) null) .build(); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } } } diff --git a/okhttp/src/test/java/okhttp3/OkHttpClientTest.java b/okhttp/src/test/java/okhttp3/OkHttpClientTest.java index 1724af3ba31c..9dd1e818f780 100644 --- a/okhttp/src/test/java/okhttp3/OkHttpClientTest.java +++ b/okhttp/src/test/java/okhttp3/OkHttpClientTest.java @@ -169,7 +169,7 @@ public final class OkHttpClientTest { try { builder.addInterceptor(null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } } @@ -178,7 +178,7 @@ public final class OkHttpClientTest { try { builder.addNetworkInterceptor(null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } } diff --git a/okhttp/src/test/java/okhttp3/RequestTest.java b/okhttp/src/test/java/okhttp3/RequestTest.java index 9638b3ba4043..4257f03bdd34 100644 --- a/okhttp/src/test/java/okhttp3/RequestTest.java +++ b/okhttp/src/test/java/okhttp3/RequestTest.java @@ -195,22 +195,22 @@ public final class RequestTest { try { builder.header(null, "Value"); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } try { builder.addHeader(null, "Value"); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } try { builder.header("Name", null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } try { builder.addHeader("Name", null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } } diff --git a/okhttp/src/test/java/okhttp3/URLConnectionTest.java b/okhttp/src/test/java/okhttp3/URLConnectionTest.java index 30e3d0213a59..95172f010316 100644 --- a/okhttp/src/test/java/okhttp3/URLConnectionTest.java +++ b/okhttp/src/test/java/okhttp3/URLConnectionTest.java @@ -156,25 +156,25 @@ public final class URLConnectionTest { new Request.Builder() .header(null, "j"); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } try { new Request.Builder() .addHeader(null, "k"); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } try { new Request.Builder() .addHeader("NullValue", null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } try { new Request.Builder() .addHeader("AnotherNullValue", null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } Response response = getResponse(request); @@ -211,7 +211,7 @@ public final class URLConnectionTest { try { response.header(null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } Headers responseHeaders = response.headers(); assertThat(new LinkedHashSet<>(responseHeaders.values("A"))).isEqualTo( @@ -3578,6 +3578,8 @@ private void zeroLengthPayload(String method) throws Exception { try { client.newBuilder().sslSocketFactory(null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } } diff --git a/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.java b/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.java index 46a107e46f33..3bc2c1857c27 100644 --- a/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.java +++ b/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.java @@ -269,7 +269,7 @@ private void checkPublicSuffix(String domain, String registrablePart) { try { publicSuffixDatabase.getEffectiveTldPlusOne(null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } return; } diff --git a/okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.java b/okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.java index 166a1263fbfa..82a2bfb9ec58 100644 --- a/okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.java +++ b/okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.java @@ -139,7 +139,7 @@ private OkHttpClientTestRule configureClientTestRule() { try { webSocket.send((String) null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } closeWebSockets(webSocket, server); @@ -156,7 +156,7 @@ private OkHttpClientTestRule configureClientTestRule() { try { webSocket.send((ByteString) null); fail(); - } catch (IllegalArgumentException expected) { + } catch (NullPointerException expected) { } closeWebSockets(webSocket, server);