diff --git a/build-logic/src/main/kotlin/okhttp.quality-conventions.gradle.kts b/build-logic/src/main/kotlin/okhttp.quality-conventions.gradle.kts index 5af682f195a5..e8c9b00fc936 100644 --- a/build-logic/src/main/kotlin/okhttp.quality-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/okhttp.quality-conventions.gradle.kts @@ -1,8 +1,6 @@ import com.vanniktech.maven.publish.MavenPublishBaseExtension -import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension -import org.gradle.api.artifacts.VersionCatalogsExtension -import org.gradle.kotlin.dsl.withType import ru.vyarus.gradle.plugin.animalsniffer.AnimalSniffer +import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension plugins { id("okhttp.base-conventions") @@ -55,6 +53,15 @@ configure { signatures = androidSignature + jvmSignature failWithoutSignatures = false + + // Android API 21 doesn't have Boolean.hashCode() (etc.) but the Android SDK will desugar these. + // https://r8.googlesource.com/r8/+/516a6684f134d06eff08080e7ef7129517071817 + ignore( + "java.lang.Boolean", + "java.lang.Integer", + "java.lang.Long", + "java.lang.Short", + ) } // Default to only published modules diff --git a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/AnyValue.kt b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/AnyValue.kt index 393946f9b5ef..ed7872f1faa2 100644 --- a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/AnyValue.kt +++ b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/AnyValue.kt @@ -27,15 +27,4 @@ internal data class AnyValue( var constructed: Boolean = false, var length: Long = -1L, val bytes: ByteString, -) { - // Avoid Long.hashCode(long) which isn't available on Android 5. - override fun hashCode(): Int { - var result = 0 - result = 31 * result + tagClass - result = 31 * result + tag.toInt() - result = 31 * result + (if (constructed) 0 else 1) - result = 31 * result + length.toInt() - result = 31 * result + bytes.hashCode() - return result - } -} +) diff --git a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/BasicDerAdapter.kt b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/BasicDerAdapter.kt index cf90b0aa369e..14c732d055f9 100644 --- a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/BasicDerAdapter.kt +++ b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/BasicDerAdapter.kt @@ -117,19 +117,6 @@ internal data class BasicDerAdapter( */ fun asTypeHint(): BasicDerAdapter = copy(typeHint = true) - // Avoid Long.hashCode(long) which isn't available on Android 5. - override fun hashCode(): Int { - var result = 0 - result = 31 * result + name.hashCode() - result = 31 * result + tagClass - result = 31 * result + tag.toInt() - result = 31 * result + codec.hashCode() - result = 31 * result + (if (isOptional) 1 else 0) - result = 31 * result + defaultValue.hashCode() - result = 31 * result + (if (typeHint) 1 else 0) - return result - } - override fun toString(): String = "$name [$tagClass/$tag]" /** Reads and writes values without knowledge of the enclosing tag, length, or defaults. */ diff --git a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/BitString.kt b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/BitString.kt index 1fc406d9dea8..2409a09a5ad3 100644 --- a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/BitString.kt +++ b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/BitString.kt @@ -24,12 +24,4 @@ internal data class BitString( val byteString: ByteString, /** 0-7 unused bits in the last byte. */ val unusedBitsCount: Int, -) { - // Avoid Long.hashCode(long) which isn't available on Android 5. - override fun hashCode(): Int { - var result = 0 - result = 31 * result + byteString.hashCode() - result = 31 * result + unusedBitsCount - return result - } -} +) diff --git a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/Certificate.kt b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/Certificate.kt index 4e69cc7b8e94..520abe63f3e2 100644 --- a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/Certificate.kt +++ b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/Certificate.kt @@ -148,15 +148,7 @@ internal data class AttributeTypeAndValue( internal data class Validity( val notBefore: Long, val notAfter: Long, -) { - // Avoid Long.hashCode(long) which isn't available on Android 5. - override fun hashCode(): Int { - var result = 0 - result = 31 * result + notBefore.toInt() - result = 31 * result + notAfter.toInt() - return result - } -} +) internal data class SubjectPublicKeyInfo( val algorithm: AlgorithmIdentifier, @@ -184,13 +176,4 @@ internal data class PrivateKeyInfo( val version: Long, val algorithmIdentifier: AlgorithmIdentifier, val privateKey: ByteString, -) { - // Avoid Long.hashCode(long) which isn't available on Android 5. - override fun hashCode(): Int { - var result = 0 - result = 31 * result + version.toInt() - result = 31 * result + algorithmIdentifier.hashCode() - result = 31 * result + privateKey.hashCode() - return result - } -} +) diff --git a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerHeader.kt b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerHeader.kt index 8bfc76106532..2f448a0b9995 100644 --- a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerHeader.kt +++ b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerHeader.kt @@ -52,16 +52,6 @@ internal data class DerHeader( val isEndOfData: Boolean get() = tagClass == TAG_CLASS_UNIVERSAL && tag == TAG_END_OF_CONTENTS - // Avoid Long.hashCode(long) which isn't available on Android 5. - override fun hashCode(): Int { - var result = 0 - result = 31 * result + tagClass - result = 31 * result + tag.toInt() - result = 31 * result + (if (constructed) 0 else 1) - result = 31 * result + length.toInt() - return result - } - override fun toString(): String = "$tagClass/$tag" companion object { diff --git a/okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/dns/-DnsMessage.kt b/okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/dns/-DnsMessage.kt index a0b1786cd96f..df84b9fe4404 100644 --- a/okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/dns/-DnsMessage.kt +++ b/okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/dns/-DnsMessage.kt @@ -33,18 +33,6 @@ data class DnsMessage( val responseCode: Int get() = (flags and 0b0000_0000_0000_1111) - // Avoid Short.hashCode(short) which isn't available on Android 5. - override fun hashCode(): Int { - var result = 0 - result = 31 * result + id - result = 31 * result + flags - result = 31 * result + questions.hashCode() - result = 31 * result + answers.hashCode() - result = 31 * result + authorityRecords.hashCode() - result = 31 * result + additionalRecords.hashCode() - return result - } - companion object { fun query( hostname: String, @@ -74,16 +62,7 @@ data class Question( val name: String, val type: Int, val `class`: Int = CLASS_IN, -) { - // Avoid Short.hashCode(short) which isn't available on Android 5. - override fun hashCode(): Int { - var result = 0 - result = 31 * result + name.hashCode() - result = 31 * result + type - result = 31 * result + `class` - return result - } -} +) sealed interface ResourceRecord { val name: String @@ -93,16 +72,7 @@ sealed interface ResourceRecord { override val name: String, override val timeToLive: Int, val address: InetAddress, - ) : ResourceRecord { - // Avoid Int.hashCode(int) which isn't available on Android 5. - override fun hashCode(): Int { - var result = 0 - result = 31 * result + name.hashCode() - result = 31 * result + timeToLive - result = 31 * result + address.hashCode() - return result - } - } + ) : ResourceRecord data class Https( override val name: String, @@ -113,21 +83,7 @@ sealed interface ResourceRecord { var port: Int = 443, val ipAddressHints: List = listOf(), val echConfigList: ByteString? = null, - ) : ResourceRecord { - // Avoid Int.hashCode(int) which isn't available on Android 5. - override fun hashCode(): Int { - var result = 0 - result = 31 * result + name.hashCode() - result = 31 * result + timeToLive - result = 31 * result + priority - result = 31 * result + targetName.hashCode() - result = 31 * result + alpnIds.hashCode() - result = 31 * result + port - result = 31 * result + ipAddressHints.hashCode() - result = 31 * result + echConfigList.hashCode() - return result - } - } + ) : ResourceRecord } /** https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4 */