From 647813705c6a29a4e3451b47ce81bb5cfc116621 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sun, 12 Apr 2020 15:14:12 +0100 Subject: [PATCH 01/19] Testing with kotlin 1.4 --- build.gradle | 36 +++++++++++-------- okcurl/src/main/kotlin/okhttp3/curl/Main.kt | 6 +--- .../okhttp3/logging/HttpLoggingInterceptor.kt | 8 ++--- .../logging/HttpLoggingInterceptorTest.java | 2 ++ .../main/kotlin/okhttp3/sse/EventSource.kt | 2 +- .../main/kotlin/okhttp3/sse/EventSources.kt | 9 ++--- .../kotlin/okhttp3/OkHttpClientTestRule.kt | 16 ++++----- .../kotlin/okhttp3/RecordingEventListener.kt | 2 +- .../src/main/kotlin/okhttp3/Authenticator.kt | 2 +- okhttp/src/main/kotlin/okhttp3/Call.kt | 2 +- .../src/main/kotlin/okhttp3/EventListener.kt | 2 +- okhttp/src/main/kotlin/okhttp3/Handshake.kt | 4 +-- okhttp/src/main/kotlin/okhttp3/Interceptor.kt | 6 ++-- okhttp/src/main/kotlin/okhttp3/WebSocket.kt | 2 +- .../src/main/kotlin/okhttp3/internal/Util.kt | 15 ++++---- .../okhttp3/internal/http2/Http2Connection.kt | 6 ++-- .../okhttp3/internal/http2/Http2Reader.kt | 2 +- .../internal/platform/BouncyCastlePlatform.kt | 2 +- .../okhttp3/internal/platform/Jdk9Platform.kt | 2 +- .../internal/platform/OpenJSSEPlatform.kt | 2 +- .../platform/android/AndroidSocketAdapter.kt | 9 +++-- .../publicsuffix/PublicSuffixDatabase.kt | 4 +-- .../tls/BasicCertificateChainCleaner.kt | 2 +- .../internal/ws/WebSocketExtensions.kt | 6 ++-- .../okhttp3/internal/ws/WebSocketReader.kt | 6 ++-- .../test/java/okhttp3/CipherSuiteTest.java | 2 ++ okhttp/src/test/java/okhttp3/CookieTest.java | 8 +++++ okhttp/src/test/java/okhttp3/HeadersTest.java | 10 ++++++ .../test/java/okhttp3/OkHttpClientTest.java | 4 +++ okhttp/src/test/java/okhttp3/RequestTest.java | 8 +++++ .../test/java/okhttp3/URLConnectionTest.java | 12 +++++++ .../PublicSuffixDatabaseTest.java | 2 ++ .../internal/ws/WebSocketHttpTest.java | 2 ++ .../okhttp3/compare/JavaHttpClientTest.kt | 2 +- 34 files changed, 121 insertions(+), 84 deletions(-) diff --git a/build.gradle b/build.gradle index 32e643f72af5..2050475171a8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -import net.ltgt.gradle.errorprone.CheckSeverity +//import net.ltgt.gradle.errorprone.CheckSeverity buildscript { ext.versions = [ @@ -15,7 +15,7 @@ buildscript { 'jnrUnixsocket': '0.28', 'jsoup': '1.13.1', 'junit': '4.13', - 'kotlin': '1.3.71', + 'kotlin': '1.4-M1', 'moshi': '1.9.2', 'okio': '2.6.0', 'ktlint': '0.36.0', @@ -39,7 +39,7 @@ buildscript { 'jsoup': "org.jsoup:jsoup:${versions.jsoup}", 'jsr305': "com.google.code.findbugs:jsr305:${versions.findbugs}", 'junit': "junit:junit:${versions.junit}", - 'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}", + 'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:1.4-M1", 'moshi': "com.squareup.moshi:moshi:${versions.moshi}", 'moshiKotlin': "com.squareup.moshi:moshi-kotlin-codegen:${versions.moshi}", 'okio': "com.squareup.okio:okio:${versions.okio}", @@ -48,7 +48,7 @@ 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-M1" 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' @@ -58,6 +58,9 @@ buildscript { mavenCentral() gradlePluginPortal() google() + maven { + url = "https://dl.bintray.com/kotlin/kotlin-eap/" + } } } @@ -97,6 +100,9 @@ allprojects { url 'https://dl.bintray.com/kotlin/dokka' } google() + maven { + url = "https://dl.bintray.com/kotlin/kotlin-eap/" + } } task downloadDependencies() { @@ -112,12 +118,14 @@ subprojects { project -> if (project.name == 'android-test') return if (project.name == 'okhttp-bom') return + apply plugin: "kotlin" 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' + // TODO raise issue +// apply plugin: 'net.ltgt.errorprone' apply plugin: 'org.jetbrains.dokka' apply plugin: 'com.diffplug.gradle.spotless' sourceCompatibility = JavaVersion.VERSION_1_8 @@ -205,20 +213,20 @@ subprojects { project -> } } - dependencies { +// dependencies { //noinspection GradleDynamicVersion - errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1' - errorprone 'com.google.errorprone:error_prone_core:2.3.4' - } +// 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 - } +// 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 afc4edbd40de..1047f01f448b 100644 --- a/okcurl/src/main/kotlin/okhttp3/curl/Main.kt +++ b/okcurl/src/main/kotlin/okhttp3/curl/Main.kt @@ -161,11 +161,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 c1a681448097..0fd5e4e3e0ab 100644 --- a/okhttp-logging-interceptor/src/main/kotlin/okhttp3/logging/HttpLoggingInterceptor.kt +++ b/okhttp-logging-interceptor/src/main/kotlin/okhttp3/logging/HttpLoggingInterceptor.kt @@ -104,17 +104,13 @@ class HttpLoggingInterceptor @JvmOverloads constructor( BODY } - interface Logger { + fun interface Logger { fun log(message: String) companion object { /** A [Logger] defaults output appropriate for the current platform. */ @JvmField - val DEFAULT: Logger = object : Logger { - override fun log(message: String) { - Platform.get().log(message) - } - } + val DEFAULT: Logger = Logger { Platform.get().log(it) } } } 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..6e017cdac68a 100644 --- a/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.java +++ b/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.java @@ -107,6 +107,8 @@ private void setLevel(Level level) { try { applicationInterceptor.setLevel(null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException 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 e7297a500c73..269ff0db4491 100644 --- a/okhttp-sse/src/main/kotlin/okhttp3/sse/EventSources.kt +++ b/okhttp-sse/src/main/kotlin/okhttp3/sse/EventSources.kt @@ -16,18 +16,15 @@ 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 { - return RealEventSource(request, listener).apply { - connect(client) - } + return EventSource.Factory { request, listener -> + RealEventSource(request, 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 0f0cca95ab36..e65ebb34a0e0 100644 --- a/okhttp-testing-support/src/main/kotlin/okhttp3/OkHttpClientTestRule.kt +++ b/okhttp-testing-support/src/main/kotlin/okhttp3/OkHttpClientTestRule.kt @@ -39,14 +39,11 @@ class OkHttpClientTestRule : TestRule { private var uncaughtException: Throwable? = null var logger: Logger? = null - 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. @@ -62,9 +59,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-testing-support/src/main/kotlin/okhttp3/RecordingEventListener.kt b/okhttp-testing-support/src/main/kotlin/okhttp3/RecordingEventListener.kt index 48ea178e083e..e65cd0424c30 100644 --- a/okhttp-testing-support/src/main/kotlin/okhttp3/RecordingEventListener.kt +++ b/okhttp-testing-support/src/main/kotlin/okhttp3/RecordingEventListener.kt @@ -125,7 +125,7 @@ open class RecordingEventListener : EventListener() { for (lock in forbiddenLocks) { assertThat(Thread.holdsLock(lock)) .overridingErrorMessage(lock.toString()) - .isFalse() + .isFalse } val startEvent = e.closes(-1L) diff --git a/okhttp/src/main/kotlin/okhttp3/Authenticator.kt b/okhttp/src/main/kotlin/okhttp3/Authenticator.kt index 43b2b416e7be..40f62766f539 100644 --- a/okhttp/src/main/kotlin/okhttp3/Authenticator.kt +++ b/okhttp/src/main/kotlin/okhttp3/Authenticator.kt @@ -96,7 +96,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/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 f89485916450..5dbd3b736e72 100644 --- a/okhttp/src/main/kotlin/okhttp3/EventListener.kt +++ b/okhttp/src/main/kotlin/okhttp3/EventListener.kt @@ -422,7 +422,7 @@ abstract class EventListener { ) { } - 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 eccae85da25e..7578955a02e9 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 @@ -299,9 +298,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 @@ -377,18 +374,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. } } @@ -472,7 +469,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/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 73a9c6e0de9d..5c28ebc9ebe7 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Reader.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Reader.kt @@ -74,7 +74,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/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/platform/android/AndroidSocketAdapter.kt b/okhttp/src/main/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt index 38b8508f30f7..280667764ff8 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt @@ -79,11 +79,10 @@ open class AndroidSocketAdapter(private val sslSocketClass: Class) val alpnResult = getAlpnSelectedProtocol.invoke(sslSocket) as ByteArray? if (alpnResult != null) String(alpnResult, StandardCharsets.UTF_8) else null } catch (e: NullPointerException) { - when { - // https://github.com/square/okhttp/issues/5587 - e.message == "ssl == null" -> null - else -> throw e - } + when (e.message) { + "ssl == null" -> null // https://github.com/square/okhttp/issues/5587 + else -> throw e + } } catch (e: IllegalAccessException) { throw AssertionError(e) } catch (e: InvocationTargetException) { diff --git a/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt b/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt index 589436c21fc2..82402af52fcb 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt @@ -191,8 +191,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..660f979d30d6 100644 --- a/okhttp/src/test/java/okhttp3/CipherSuiteTest.java +++ b/okhttp/src/test/java/okhttp3/CipherSuiteTest.java @@ -31,6 +31,8 @@ public class CipherSuiteTest { try { forJavaName(null); fail("Should have thrown"); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } } diff --git a/okhttp/src/test/java/okhttp3/CookieTest.java b/okhttp/src/test/java/okhttp3/CookieTest.java index bf2add65e3a9..13792257b6fd 100644 --- a/okhttp/src/test/java/okhttp3/CookieTest.java +++ b/okhttp/src/test/java/okhttp3/CookieTest.java @@ -427,6 +427,8 @@ public final class CookieTest { try { new Cookie.Builder().name(null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } try { @@ -440,6 +442,8 @@ public final class CookieTest { try { new Cookie.Builder().value(null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } try { @@ -485,6 +489,8 @@ public final class CookieTest { try { new Cookie.Builder().hostOnlyDomain(null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } try { @@ -518,6 +524,8 @@ public final class CookieTest { try { new Cookie.Builder().path(null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } try { diff --git a/okhttp/src/test/java/okhttp3/HeadersTest.java b/okhttp/src/test/java/okhttp3/HeadersTest.java index 6ada63c49147..79a9861d067f 100644 --- a/okhttp/src/test/java/okhttp3/HeadersTest.java +++ b/okhttp/src/test/java/okhttp3/HeadersTest.java @@ -201,6 +201,8 @@ public final class HeadersTest { try { Headers.of(Collections.singletonMap("User-Agent", null)); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (TypeCastException expected) { } } @@ -831,6 +833,8 @@ public final class HeadersTest { .add("testDate", (Date) null) .build(); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } } @@ -850,6 +854,8 @@ public final class HeadersTest { .add("Test-Instant", (Instant) null) .build(); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } } @@ -870,6 +876,8 @@ public final class HeadersTest { .set("testDate", (Date) null) .build(); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } } @@ -890,6 +898,8 @@ public final class HeadersTest { .set("Test-Instant", (Instant) null) .build(); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } } diff --git a/okhttp/src/test/java/okhttp3/OkHttpClientTest.java b/okhttp/src/test/java/okhttp3/OkHttpClientTest.java index 1724af3ba31c..93b0a866d47e 100644 --- a/okhttp/src/test/java/okhttp3/OkHttpClientTest.java +++ b/okhttp/src/test/java/okhttp3/OkHttpClientTest.java @@ -169,6 +169,8 @@ public final class OkHttpClientTest { try { builder.addInterceptor(null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } } @@ -178,6 +180,8 @@ public final class OkHttpClientTest { try { builder.addNetworkInterceptor(null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } } diff --git a/okhttp/src/test/java/okhttp3/RequestTest.java b/okhttp/src/test/java/okhttp3/RequestTest.java index 9638b3ba4043..49a7e9468dfe 100644 --- a/okhttp/src/test/java/okhttp3/RequestTest.java +++ b/okhttp/src/test/java/okhttp3/RequestTest.java @@ -195,21 +195,29 @@ public final class RequestTest { try { builder.header(null, "Value"); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } try { builder.addHeader(null, "Value"); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } try { builder.header("Name", null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } try { builder.addHeader("Name", null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } } diff --git a/okhttp/src/test/java/okhttp3/URLConnectionTest.java b/okhttp/src/test/java/okhttp3/URLConnectionTest.java index 18ddaa44263d..1e0f8b838662 100644 --- a/okhttp/src/test/java/okhttp3/URLConnectionTest.java +++ b/okhttp/src/test/java/okhttp3/URLConnectionTest.java @@ -156,24 +156,32 @@ public final class URLConnectionTest { new Request.Builder() .header(null, "j"); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } try { new Request.Builder() .addHeader(null, "k"); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } try { new Request.Builder() .addHeader("NullValue", null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } try { new Request.Builder() .addHeader("AnotherNullValue", null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } @@ -211,6 +219,8 @@ public final class URLConnectionTest { try { response.header(null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } Headers responseHeaders = response.headers(); @@ -3578,6 +3588,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..2c986d494800 100644 --- a/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.java +++ b/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.java @@ -269,6 +269,8 @@ private void checkPublicSuffix(String domain, String registrablePart) { try { publicSuffixDatabase.getEffectiveTldPlusOne(null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException 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 226477f9cf4f..c4dd496c04e8 100644 --- a/okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.java +++ b/okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.java @@ -147,6 +147,8 @@ public final class WebSocketHttpTest { try { webSocket.send((ByteString) null); fail(); + } catch (NullPointerException expected) { + // Kotlin 1.4 } catch (IllegalArgumentException expected) { } diff --git a/samples/compare/src/test/kotlin/okhttp3/compare/JavaHttpClientTest.kt b/samples/compare/src/test/kotlin/okhttp3/compare/JavaHttpClientTest.kt index 12b111ba41ff..d862505788b3 100644 --- a/samples/compare/src/test/kotlin/okhttp3/compare/JavaHttpClientTest.kt +++ b/samples/compare/src/test/kotlin/okhttp3/compare/JavaHttpClientTest.kt @@ -56,7 +56,7 @@ class JavaHttpClientTest { assertThat(recorded.getHeader("Accept-Encoding")).isNull() // No built-in gzip. assertThat(recorded.getHeader("Connection")).isEqualTo("Upgrade, HTTP2-Settings") assertThat(recorded.getHeader("Content-Length")).isEqualTo("0") - assertThat(recorded.getHeader("HTTP2-Settings")).isNotNull() + assertThat(recorded.getHeader("HTTP2-Settings")).isNotNull assertThat(recorded.getHeader("Upgrade")).isEqualTo("h2c") // HTTP/2 over plaintext! assertThat(recorded.getHeader("User-Agent")).matches("Java-http-client/.*") } From e699affe8a7e3175095fd87c3f892e091c2850ea Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Wed, 13 May 2020 20:03:48 +0100 Subject: [PATCH 02/19] Fix --- okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.java b/okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.java index b1d22679defb..ef5f364d3635 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 | IllegalArgumentException expected) { } closeWebSockets(webSocket, server); From ecbcf8e70c88588bebd018b99966f3a244a62a67 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Thu, 14 May 2020 19:05:57 +0100 Subject: [PATCH 03/19] M2 dev builds --- build.gradle | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 2050475171a8..2ca908add94b 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { 'jnrUnixsocket': '0.28', 'jsoup': '1.13.1', 'junit': '4.13', - 'kotlin': '1.4-M1', + 'kotlin': '1.4-M2-eap-72', 'moshi': '1.9.2', 'okio': '2.6.0', 'ktlint': '0.36.0', @@ -39,7 +39,7 @@ buildscript { 'jsoup': "org.jsoup:jsoup:${versions.jsoup}", 'jsr305': "com.google.code.findbugs:jsr305:${versions.findbugs}", 'junit': "junit:junit:${versions.junit}", - 'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:1.4-M1", + 'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:1.4-M2-eap-72", 'moshi': "com.squareup.moshi:moshi:${versions.moshi}", 'moshiKotlin': "com.squareup.moshi:moshi-kotlin-codegen:${versions.moshi}", 'okio': "com.squareup.okio:okio:${versions.okio}", @@ -48,10 +48,10 @@ buildscript { dependencies { classpath 'net.ltgt.gradle:gradle-errorprone-plugin:1.1.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M1" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M2-eap-72" 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.diffplug.spotless:spotless-plugin-gradle:3.28.1' + classpath 'com.android.tools.build:gradle:3.6.3' } repositories { @@ -59,7 +59,7 @@ buildscript { gradlePluginPortal() google() maven { - url = "https://dl.bintray.com/kotlin/kotlin-eap/" + url = "https://dl.bintray.com/kotlin/kotlin-dev/" } } } @@ -101,7 +101,7 @@ allprojects { } google() maven { - url = "https://dl.bintray.com/kotlin/kotlin-eap/" + url = "https://dl.bintray.com/kotlin/kotlin-dev/" } } From ef4e0ba6802a924872521e6be3a43595553c0f5c Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Thu, 4 Jun 2020 08:01:33 +0100 Subject: [PATCH 04/19] Allow for domain name trailing dot in PublicSuffixDatabase (#6111) --- .../publicsuffix/PublicSuffixDatabase.kt | 16 ++++++++++++++-- okhttp/src/test/java/okhttp3/HttpUrlTest.java | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt b/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt index 589436c21fc2..614fd818eb71 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt @@ -67,7 +67,8 @@ class PublicSuffixDatabase { fun getEffectiveTldPlusOne(domain: String): String? { // We use UTF-8 in the list so we need to convert to Unicode. val unicodeDomain = IDN.toUnicode(domain) - val domainLabels = unicodeDomain.split('.') + val domainLabels = splitDomain(unicodeDomain) + val rule = findMatchingRule(domainLabels) if (domainLabels.size == rule.size && rule[0][0] != EXCEPTION_MARKER) { return null // The domain is a public suffix. @@ -81,7 +82,18 @@ class PublicSuffixDatabase { domainLabels.size - (rule.size + 1) } - return domain.split('.').asSequence().drop(firstLabelOffset).joinToString(".") + return splitDomain(domain).asSequence().drop(firstLabelOffset).joinToString(".") + } + + private fun splitDomain(domain: String): List { + val domainLabels = domain.split('.') + + if (domainLabels.last() == "") { + // allow for domain name trailing dot + return domainLabels.dropLast(1) + } + + return domainLabels } private fun findMatchingRule(domainLabels: List): List { diff --git a/okhttp/src/test/java/okhttp3/HttpUrlTest.java b/okhttp/src/test/java/okhttp3/HttpUrlTest.java index 7e5816dfa3d7..ff10f31d975a 100644 --- a/okhttp/src/test/java/okhttp3/HttpUrlTest.java +++ b/okhttp/src/test/java/okhttp3/HttpUrlTest.java @@ -1756,6 +1756,21 @@ HttpUrl parse(String url) { assertThat(parse("https://xn--4pvxs.jp").topPrivateDomain()).isNull(); assertThat(parse("https://localhost").topPrivateDomain()).isNull(); assertThat(parse("https://127.0.0.1").topPrivateDomain()).isNull(); + + // https://github.com/square/okhttp/issues/6109 + assertThat(parse("http://a./").topPrivateDomain()).isNull(); + assertThat(parse("http://./").topPrivateDomain()).isNull(); + + assertThat(parse("http://squareup.com./").topPrivateDomain()).isEqualTo("squareup.com"); + } + + @Test + public void unparseableTopPrivateDomain() { + assertInvalid("http://a../", "Invalid URL host: \"a..\""); + assertInvalid("http://..a/", "Invalid URL host: \"..a\""); + assertInvalid("http://a..b/", "Invalid URL host: \"a..b\""); + assertInvalid("http://.a/", "Invalid URL host: \".a\""); + assertInvalid("http://../", "Invalid URL host: \"..\""); } private void assertInvalid(String string, String exceptionMessage) { From a3ab5d284fa04b2775af0313099dbe963a08c431 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Thu, 4 Jun 2020 08:02:39 +0100 Subject: [PATCH 05/19] Dependency upgrades (#6114) --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 8c66726bd549..70db99b6f19a 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { 'jnrUnixsocket': '0.28', 'jsoup': '1.13.1', 'junit': '4.13', - 'kotlin': '1.3.71', + 'kotlin': '1.3.72', 'moshi': '1.9.2', 'okio': '2.6.0', 'ktlint': '0.36.0', diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fd0c5a38e92d..186b71557c50 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 4051d94874ecb1503a284a4f08eae31588fda6c1 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Thu, 4 Jun 2020 18:58:49 +0100 Subject: [PATCH 06/19] Update build.gradle --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 2ca908add94b..a3cd8a037f91 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { 'jnrUnixsocket': '0.28', 'jsoup': '1.13.1', 'junit': '4.13', - 'kotlin': '1.4-M2-eap-72', + 'kotlin': '1.4-M2', 'moshi': '1.9.2', 'okio': '2.6.0', 'ktlint': '0.36.0', @@ -39,7 +39,7 @@ buildscript { 'jsoup': "org.jsoup:jsoup:${versions.jsoup}", 'jsr305': "com.google.code.findbugs:jsr305:${versions.findbugs}", 'junit': "junit:junit:${versions.junit}", - 'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:1.4-M2-eap-72", + 'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:1.4-M2", 'moshi': "com.squareup.moshi:moshi:${versions.moshi}", 'moshiKotlin': "com.squareup.moshi:moshi-kotlin-codegen:${versions.moshi}", 'okio': "com.squareup.okio:okio:${versions.okio}", @@ -48,7 +48,7 @@ buildscript { dependencies { classpath 'net.ltgt.gradle:gradle-errorprone-plugin:1.1.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M2-eap-72" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M2" classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1" classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.28.1' classpath 'com.android.tools.build:gradle:3.6.3' From 9aa4564d4dd48a31e36c5503e4bbca0871511864 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Thu, 4 Jun 2020 19:45:34 +0100 Subject: [PATCH 07/19] 1.4 M2 --- build.gradle | 29 ++++++++++++++--------------- okhttp/build.gradle | 2 ++ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 10876ab47ea8..aa95a9c41edf 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ buildscript { 'kotlin': '1.4-M2', 'moshi': '1.9.2', 'okio': '2.6.0', - 'ktlint': '0.36.0', + 'ktlint': '0.37.0', 'picocli': '4.2.0', 'openjsse': '1.1.0' ] @@ -47,10 +47,10 @@ buildscript { ] dependencies { - classpath 'net.ltgt.gradle:gradle-errorprone-plugin:1.1.1' + classpath 'net.ltgt.gradle:gradle-errorprone-plugin:1.2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M2" classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1" - classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.28.1' + classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.30.0' classpath 'com.android.tools.build:gradle:3.6.3' } @@ -124,10 +124,9 @@ subprojects { project -> apply plugin: 'org.jetbrains.kotlin.platform.jvm' apply plugin: 'checkstyle' apply plugin: 'ru.vyarus.animalsniffer' - // TODO raise issue // apply plugin: 'net.ltgt.errorprone' apply plugin: 'org.jetbrains.dokka' - apply plugin: 'com.diffplug.gradle.spotless' +// apply plugin: 'com.diffplug.gradle.spotless' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 @@ -160,12 +159,12 @@ 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']) - } - } +// 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 { @@ -214,17 +213,17 @@ subprojects { project -> } // dependencies { - //noinspection GradleDynamicVersion +// //noinspection GradleDynamicVersion // errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1' -// errorprone 'com.google.errorprone:error_prone_core:2.3.4' +// errorprone 'com.google.errorprone:error_prone_core:2.4.0' // } tasks.withType(JavaCompile).configureEach { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 // options.errorprone { -// check("MissingFail", CheckSeverity.ERROR) -// check("MissingOverride", CheckSeverity.ERROR) +// check("MissingFail", net.ltgt.gradle.errorprone.CheckSeverity.ERROR) +// check("MissingOverride", net.ltgt.gradle.errorprone.CheckSeverity.ERROR) // enabled = JavaVersion.current() < JavaVersion.VERSION_12 // } } 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) From 9ce8ca30ca4e38209c78cba952285d313fbf3135 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Tue, 7 Jul 2020 12:05:13 +0100 Subject: [PATCH 08/19] Fix --- .../internal/platform/android/AndroidSocketAdapter.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/okhttp/src/main/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt b/okhttp/src/main/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt index 78cd9d160250..35a38641355a 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt @@ -81,14 +81,9 @@ open class AndroidSocketAdapter(private val sslSocketClass: Class) val alpnResult = getAlpnSelectedProtocol.invoke(sslSocket) as ByteArray? if (alpnResult != null) String(alpnResult, StandardCharsets.UTF_8) else null } catch (e: NullPointerException) { -<<<<<<< HEAD - when (e.message) { - "ssl == null" -> null // https://github.com/square/okhttp/issues/5587 -======= when { // https://github.com/square/okhttp/issues/5587 e.message == "ssl == null" -> null ->>>>>>> master else -> throw e } } catch (e: IllegalAccessException) { From 248f800d9eaac676f52563186eb8f0c5905d2e45 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Tue, 7 Jul 2020 12:08:18 +0100 Subject: [PATCH 09/19] Cleanup --- okhttp/src/main/kotlin/okhttp3/Cache.kt | 13 ++++++------- .../kotlin/okhttp3/internal/connection/Exchange.kt | 2 +- .../okhttp3/internal/http1/Http1ExchangeCodec.kt | 6 +++--- .../internal/platform/Jdk8WithJettyBootPlatform.kt | 6 +++--- 4 files changed, 13 insertions(+), 14 deletions(-) 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/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/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? { From aa04573c2cd00c3b085f9e78e1a40f5117a1907d Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Fri, 24 Jul 2020 19:51:41 +0100 Subject: [PATCH 10/19] Kotlin 1.4 RC --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 42f8d0e7fbcb..35cef137656a 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { 'jnrUnixsocket': '0.28', 'jsoup': '1.13.1', 'junit': '4.13', - 'kotlin': '1.4-M3', + 'kotlin': '1.4.0-rc', 'moshi': '1.9.2', 'okio': '2.6.0', 'ktlint': '0.37.0', @@ -39,7 +39,7 @@ buildscript { 'jsoup': "org.jsoup:jsoup:${versions.jsoup}", 'jsr305': "com.google.code.findbugs:jsr305:${versions.findbugs}", 'junit': "junit:junit:${versions.junit}", - 'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:1.4-M3", + 'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:1.4.0-rc", 'moshi': "com.squareup.moshi:moshi:${versions.moshi}", 'moshiKotlin': "com.squareup.moshi:moshi-kotlin-codegen:${versions.moshi}", 'okio': "com.squareup.okio:okio:${versions.okio}", @@ -48,7 +48,7 @@ buildscript { dependencies { classpath 'net.ltgt.gradle:gradle-errorprone-plugin:1.2.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M3" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0-rc" classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1" classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.30.0' classpath 'com.android.tools.build:gradle:3.6.3' From cee4faf1828417909acf0919f286f9774d787126 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 1 Aug 2020 07:34:05 +0100 Subject: [PATCH 11/19] More fixes --- build.gradle | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 09c560dea5fe..776a61a3853b 100644 --- a/build.gradle +++ b/build.gradle @@ -51,7 +51,7 @@ buildscript { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0-rc" classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1" classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.30.0' - classpath 'com.android.tools.build:gradle:3.6.3' + classpath 'com.android.tools.build:gradle:3.6.4' } repositories { @@ -121,7 +121,6 @@ subprojects { project -> apply plugin: "kotlin" 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' @@ -169,6 +168,8 @@ subprojects { project -> tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { kotlinOptions { jvmTarget = "1.8" + apiVersion = "1.4" + languageVersion = "1.4" } } From 56622fa00737913de6f4592a98400f62f5bb5170 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 15 Aug 2020 10:07:25 +0100 Subject: [PATCH 12/19] Kotlin 1.4.0 --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 776a61a3853b..ab4f61da2484 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { 'jnrUnixsocket': '0.28', 'jsoup': '1.13.1', 'junit': '4.13', - 'kotlin': '1.4.0-rc', + 'kotlin': '1.4.0', 'moshi': '1.9.2', 'okio': '2.7.0', 'ktlint': '0.37.0', @@ -39,7 +39,7 @@ buildscript { 'jsoup': "org.jsoup:jsoup:${versions.jsoup}", 'jsr305': "com.google.code.findbugs:jsr305:${versions.findbugs}", 'junit': "junit:junit:${versions.junit}", - 'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:1.4.0-rc", + 'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:1.4.0", 'moshi': "com.squareup.moshi:moshi:${versions.moshi}", 'moshiKotlin': "com.squareup.moshi:moshi-kotlin-codegen:${versions.moshi}", 'okio': "com.squareup.okio:okio:${versions.okio}", @@ -48,7 +48,7 @@ buildscript { dependencies { classpath 'net.ltgt.gradle:gradle-errorprone-plugin:1.2.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0-rc" + 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.30.0' classpath 'com.android.tools.build:gradle:3.6.4' From 0e343e2eeca8614197d603a76688865808a3745e Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 15 Aug 2020 10:25:55 +0100 Subject: [PATCH 13/19] Readd plugins --- build.gradle | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index ab4f61da2484..5444c4479789 100644 --- a/build.gradle +++ b/build.gradle @@ -47,10 +47,8 @@ buildscript { ] dependencies { - classpath 'net.ltgt.gradle:gradle-errorprone-plugin:1.2.1' 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.30.0' classpath 'com.android.tools.build:gradle:3.6.4' } @@ -68,6 +66,8 @@ 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 "com.diffplug.spotless" version "5.1.1" + id("net.ltgt.errorprone") version "1.2.1" } /** Returns the artifact ID for the project, or null if it is not published. */ @@ -123,9 +123,7 @@ subprojects { project -> apply plugin: 'java-library' 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 From 557666a90712a0ed10bd3deb1f1cbeada354c7fe Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 22 Aug 2020 07:26:33 +0100 Subject: [PATCH 14/19] Review comments --- build.gradle | 32 +++++++------------ .../logging/HttpLoggingInterceptorTest.java | 2 -- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/build.gradle b/build.gradle index 80256cb340f3..d1d51bcf53f9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//import net.ltgt.gradle.errorprone.CheckSeverity +import net.ltgt.gradle.errorprone.CheckSeverity buildscript { ext.versions = [ @@ -18,7 +18,7 @@ buildscript { 'kotlin': '1.4.0', 'moshi': '1.9.2', 'okio': '2.7.0', - 'ktlint': '0.37.0', + 'ktlint': '0.38.0', 'picocli': '4.2.0', 'openjsse': '1.1.0' ] @@ -39,7 +39,7 @@ buildscript { 'jsoup': "org.jsoup:jsoup:${versions.jsoup}", 'jsr305': "com.google.code.findbugs:jsr305:${versions.findbugs}", 'junit': "junit:junit:${versions.junit}", - 'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:1.4.0", + 'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}", 'moshi': "com.squareup.moshi:moshi:${versions.moshi}", 'moshiKotlin': "com.squareup.moshi:moshi-kotlin-codegen:${versions.moshi}", 'okio': "com.squareup.okio:okio:${versions.okio}", @@ -49,16 +49,13 @@ buildscript { dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0" classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1" - classpath 'com.android.tools.build:gradle:3.6.4' + classpath 'com.android.tools.build:gradle:4.0.1' } repositories { mavenCentral() gradlePluginPortal() google() - maven { - url = "https://dl.bintray.com/kotlin/kotlin-dev/" - } } } @@ -66,7 +63,7 @@ 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 "com.diffplug.spotless" version "5.1.1" + id "com.diffplug.spotless" version "5.1.2" id("net.ltgt.errorprone") version "1.2.1" } @@ -100,9 +97,6 @@ allprojects { url 'https://dl.bintray.com/kotlin/dokka' } google() - maven { - url = "https://dl.bintray.com/kotlin/kotlin-dev/" - } } task downloadDependencies() { @@ -118,7 +112,7 @@ subprojects { project -> if (project.name == 'android-test') return if (project.name == 'okhttp-bom') return - apply plugin: "kotlin" + apply plugin: "org.jetbrains.kotlin.jvm" apply plugin: 'java' apply plugin: 'java-library' apply plugin: 'checkstyle' @@ -156,18 +150,16 @@ 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']) -// } -// } + 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" - apiVersion = "1.4" - languageVersion = "1.4" } } 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 6e017cdac68a..2cb920a07675 100644 --- a/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.java +++ b/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.java @@ -108,8 +108,6 @@ private void setLevel(Level level) { applicationInterceptor.setLevel(null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } } From d4b74c17faa55749fecd4ca07225d5d4aad79dd6 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 22 Aug 2020 07:39:33 +0100 Subject: [PATCH 15/19] Review comments --- .editorconfig | 2 ++ build.gradle | 7 ------- 2 files changed, 2 insertions(+), 7 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000000..cee98f01ef20 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,2 @@ +[*.kt] +indent_size = 2 \ No newline at end of file diff --git a/build.gradle b/build.gradle index d1d51bcf53f9..f6a4cbc4a730 100644 --- a/build.gradle +++ b/build.gradle @@ -150,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" From dddb1490cb5d37f1ff3378f8de6f2aa24980b83e Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 22 Aug 2020 07:48:06 +0100 Subject: [PATCH 16/19] Review comments --- .editorconfig | 2 +- build.gradle | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.editorconfig b/.editorconfig index cee98f01ef20..0067d4488ef2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,2 +1,2 @@ [*.kt] -indent_size = 2 \ No newline at end of file +indent_size = 2 diff --git a/build.gradle b/build.gradle index f6a4cbc4a730..2570639036b9 100644 --- a/build.gradle +++ b/build.gradle @@ -49,7 +49,7 @@ buildscript { dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0" classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1" - classpath 'com.android.tools.build:gradle:4.0.1' + classpath "com.android.tools.build:gradle:4.0.1" } repositories { @@ -60,11 +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" + id "net.ltgt.errorprone" version "1.2.1" } /** Returns the artifact ID for the project, or null if it is not published. */ From f1f28f908766557fbfc2109e18c2a83bf86e70dc Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sun, 6 Sep 2020 06:11:46 +0100 Subject: [PATCH 17/19] Bump to okio 2.8.0 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 80256cb340f3..4607c740b588 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { 'junit': '4.13', 'kotlin': '1.4.0', 'moshi': '1.9.2', - 'okio': '2.7.0', + 'okio': '2.8.0', 'ktlint': '0.37.0', 'picocli': '4.2.0', 'openjsse': '1.1.0' From ef1229d25a5f33bc66c061791f54b5166d4bf0ba Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sun, 6 Sep 2020 16:12:40 +0100 Subject: [PATCH 18/19] Review comments --- build.gradle | 11 ----------- .../src/main/kotlin/okhttp3/RecordingEventListener.kt | 2 +- okhttp/src/test/java/okhttp3/CipherSuiteTest.java | 2 -- okhttp/src/test/java/okhttp3/HeadersTest.java | 7 ------- 4 files changed, 1 insertion(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index 6626d00ea550..9e8df402ea93 100644 --- a/build.gradle +++ b/build.gradle @@ -196,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.4.0' -// } tasks.withType(JavaCompile).configureEach { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 - -// options.errorprone { -// check("MissingFail", net.ltgt.gradle.errorprone.CheckSeverity.ERROR) -// check("MissingOverride", net.ltgt.gradle.errorprone.CheckSeverity.ERROR) -// enabled = JavaVersion.current() < JavaVersion.VERSION_12 -// } } dokka { diff --git a/okhttp-testing-support/src/main/kotlin/okhttp3/RecordingEventListener.kt b/okhttp-testing-support/src/main/kotlin/okhttp3/RecordingEventListener.kt index 4827dcef0fc0..922e796e0aad 100644 --- a/okhttp-testing-support/src/main/kotlin/okhttp3/RecordingEventListener.kt +++ b/okhttp-testing-support/src/main/kotlin/okhttp3/RecordingEventListener.kt @@ -129,7 +129,7 @@ open class RecordingEventListener : EventListener() { for (lock in forbiddenLocks) { assertThat(Thread.holdsLock(lock)) .overridingErrorMessage(lock.toString()) - .isFalse + .isFalse() } val startEvent = e.closes(-1L) diff --git a/okhttp/src/test/java/okhttp3/CipherSuiteTest.java b/okhttp/src/test/java/okhttp3/CipherSuiteTest.java index 660f979d30d6..cf3dd0c179cd 100644 --- a/okhttp/src/test/java/okhttp3/CipherSuiteTest.java +++ b/okhttp/src/test/java/okhttp3/CipherSuiteTest.java @@ -32,8 +32,6 @@ public class CipherSuiteTest { forJavaName(null); fail("Should have thrown"); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } } diff --git a/okhttp/src/test/java/okhttp3/HeadersTest.java b/okhttp/src/test/java/okhttp3/HeadersTest.java index 79a9861d067f..7ecebdbbe782 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; @@ -203,7 +201,6 @@ public final class HeadersTest { fail(); } catch (NullPointerException expected) { // Kotlin 1.4 - } catch (TypeCastException expected) { } } @@ -835,7 +832,6 @@ public final class HeadersTest { fail(); } catch (NullPointerException expected) { // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } } @@ -856,7 +852,6 @@ public final class HeadersTest { fail(); } catch (NullPointerException expected) { // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } } @@ -878,7 +873,6 @@ public final class HeadersTest { fail(); } catch (NullPointerException expected) { // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } } @@ -900,7 +894,6 @@ public final class HeadersTest { fail(); } catch (NullPointerException expected) { // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } } } From 59b8b9f77f90b747c483eb9680a3cb450d2988c7 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sun, 6 Sep 2020 16:30:23 +0100 Subject: [PATCH 19/19] Review comments --- okhttp/src/test/java/okhttp3/CookieTest.java | 8 -------- okhttp/src/test/java/okhttp3/HeadersTest.java | 5 ----- okhttp/src/test/java/okhttp3/OkHttpClientTest.java | 4 ---- okhttp/src/test/java/okhttp3/RequestTest.java | 8 -------- okhttp/src/test/java/okhttp3/URLConnectionTest.java | 10 ---------- .../publicsuffix/PublicSuffixDatabaseTest.java | 2 -- .../java/okhttp3/internal/ws/WebSocketHttpTest.java | 4 +--- .../test/kotlin/okhttp3/compare/JavaHttpClientTest.kt | 2 +- 8 files changed, 2 insertions(+), 41 deletions(-) diff --git a/okhttp/src/test/java/okhttp3/CookieTest.java b/okhttp/src/test/java/okhttp3/CookieTest.java index 13792257b6fd..e90343610746 100644 --- a/okhttp/src/test/java/okhttp3/CookieTest.java +++ b/okhttp/src/test/java/okhttp3/CookieTest.java @@ -428,8 +428,6 @@ public final class CookieTest { new Cookie.Builder().name(null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } try { new Cookie.Builder().name(" a "); @@ -443,8 +441,6 @@ public final class CookieTest { new Cookie.Builder().value(null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } try { new Cookie.Builder().value(" b "); @@ -490,8 +486,6 @@ public final class CookieTest { new Cookie.Builder().hostOnlyDomain(null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } try { new Cookie.Builder().hostOnlyDomain("a/b"); @@ -525,8 +519,6 @@ public final class CookieTest { new Cookie.Builder().path(null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException 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 7ecebdbbe782..cbb86ae8c570 100644 --- a/okhttp/src/test/java/okhttp3/HeadersTest.java +++ b/okhttp/src/test/java/okhttp3/HeadersTest.java @@ -200,7 +200,6 @@ public final class HeadersTest { Headers.of(Collections.singletonMap("User-Agent", null)); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 } } @@ -831,7 +830,6 @@ public final class HeadersTest { .build(); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 } } @@ -851,7 +849,6 @@ public final class HeadersTest { .build(); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 } } @@ -872,7 +869,6 @@ public final class HeadersTest { .build(); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 } } @@ -893,7 +889,6 @@ public final class HeadersTest { .build(); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 } } } diff --git a/okhttp/src/test/java/okhttp3/OkHttpClientTest.java b/okhttp/src/test/java/okhttp3/OkHttpClientTest.java index 93b0a866d47e..9dd1e818f780 100644 --- a/okhttp/src/test/java/okhttp3/OkHttpClientTest.java +++ b/okhttp/src/test/java/okhttp3/OkHttpClientTest.java @@ -170,8 +170,6 @@ public final class OkHttpClientTest { builder.addInterceptor(null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } } @@ -181,8 +179,6 @@ public final class OkHttpClientTest { builder.addNetworkInterceptor(null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } } diff --git a/okhttp/src/test/java/okhttp3/RequestTest.java b/okhttp/src/test/java/okhttp3/RequestTest.java index 49a7e9468dfe..4257f03bdd34 100644 --- a/okhttp/src/test/java/okhttp3/RequestTest.java +++ b/okhttp/src/test/java/okhttp3/RequestTest.java @@ -196,29 +196,21 @@ public final class RequestTest { builder.header(null, "Value"); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } try { builder.addHeader(null, "Value"); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } try { builder.header("Name", null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } try { builder.addHeader("Name", null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } } diff --git a/okhttp/src/test/java/okhttp3/URLConnectionTest.java b/okhttp/src/test/java/okhttp3/URLConnectionTest.java index d6914db72459..95172f010316 100644 --- a/okhttp/src/test/java/okhttp3/URLConnectionTest.java +++ b/okhttp/src/test/java/okhttp3/URLConnectionTest.java @@ -157,32 +157,24 @@ public final class URLConnectionTest { .header(null, "j"); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } try { new Request.Builder() .addHeader(null, "k"); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } try { new Request.Builder() .addHeader("NullValue", null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } try { new Request.Builder() .addHeader("AnotherNullValue", null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } Response response = getResponse(request); @@ -220,8 +212,6 @@ public final class URLConnectionTest { response.header(null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } Headers responseHeaders = response.headers(); assertThat(new LinkedHashSet<>(responseHeaders.values("A"))).isEqualTo( diff --git a/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.java b/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.java index 2c986d494800..3bc2c1857c27 100644 --- a/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.java +++ b/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.java @@ -270,8 +270,6 @@ private void checkPublicSuffix(String domain, String registrablePart) { publicSuffixDatabase.getEffectiveTldPlusOne(null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException 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 ef5f364d3635..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 (NullPointerException | IllegalArgumentException expected) { + } catch (NullPointerException expected) { } closeWebSockets(webSocket, server); @@ -157,8 +157,6 @@ private OkHttpClientTestRule configureClientTestRule() { webSocket.send((ByteString) null); fail(); } catch (NullPointerException expected) { - // Kotlin 1.4 - } catch (IllegalArgumentException expected) { } closeWebSockets(webSocket, server); diff --git a/samples/compare/src/test/kotlin/okhttp3/compare/JavaHttpClientTest.kt b/samples/compare/src/test/kotlin/okhttp3/compare/JavaHttpClientTest.kt index d862505788b3..12b111ba41ff 100644 --- a/samples/compare/src/test/kotlin/okhttp3/compare/JavaHttpClientTest.kt +++ b/samples/compare/src/test/kotlin/okhttp3/compare/JavaHttpClientTest.kt @@ -56,7 +56,7 @@ class JavaHttpClientTest { assertThat(recorded.getHeader("Accept-Encoding")).isNull() // No built-in gzip. assertThat(recorded.getHeader("Connection")).isEqualTo("Upgrade, HTTP2-Settings") assertThat(recorded.getHeader("Content-Length")).isEqualTo("0") - assertThat(recorded.getHeader("HTTP2-Settings")).isNotNull + assertThat(recorded.getHeader("HTTP2-Settings")).isNotNull() assertThat(recorded.getHeader("Upgrade")).isEqualTo("h2c") // HTTP/2 over plaintext! assertThat(recorded.getHeader("User-Agent")).matches("Java-http-client/.*") }