From 708d89b9eaead6de2ea5a1b3aad1c2e8e8b77e05 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Fri, 15 Sep 2023 14:51:38 +0100 Subject: [PATCH] Make Public Suffix Database failures permanent (#7828) --- .../publicsuffix/PublicSuffixDatabase.kt | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt b/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt index 451f67e60ae7..8b1aa1918cc0 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt @@ -203,26 +203,28 @@ class PublicSuffixDatabase { @Throws(IOException::class) private fun readTheList() { - var publicSuffixListBytes: ByteArray? - var publicSuffixExceptionListBytes: ByteArray? + try { + var publicSuffixListBytes: ByteArray? + var publicSuffixExceptionListBytes: ByteArray? - val resource = + val resource = PublicSuffixDatabase::class.java.getResourceAsStream(PUBLIC_SUFFIX_RESOURCE) ?: return - GzipSource(resource.source()).buffer().use { bufferedSource -> - val totalBytes = bufferedSource.readInt() - publicSuffixListBytes = bufferedSource.readByteArray(totalBytes.toLong()) + GzipSource(resource.source()).buffer().use { bufferedSource -> + val totalBytes = bufferedSource.readInt() + publicSuffixListBytes = bufferedSource.readByteArray(totalBytes.toLong()) - val totalExceptionBytes = bufferedSource.readInt() - publicSuffixExceptionListBytes = bufferedSource.readByteArray(totalExceptionBytes.toLong()) - } + val totalExceptionBytes = bufferedSource.readInt() + publicSuffixExceptionListBytes = bufferedSource.readByteArray(totalExceptionBytes.toLong()) + } - synchronized(this) { - this.publicSuffixListBytes = publicSuffixListBytes!! - this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes!! + synchronized(this) { + this.publicSuffixListBytes = publicSuffixListBytes!! + this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes!! + } + } finally { + readCompleteLatch.countDown() } - - readCompleteLatch.countDown() } /** Visible for testing. */