diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c2f5045e86..2e892c236e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -76,4 +76,3 @@ mockito = { module = "org.mockito:mockito-core", version = "3.5.10" } mockitoKotlin = { module = "com.nhaarman.mockitokotlin2:mockito-kotlin", version = "2.2.0" } robolectric = { module = "org.robolectric:robolectric", version = "4.0-alpha-3" } okio2 = { module = "com.squareup.okio:okio", version = "2.2.2" } -okio1 = { module = "com.squareup.okio:okio", version = "1.14.0" } diff --git a/shark/shark-graph/src/main/java/shark/HeapObject.kt b/shark/shark-graph/src/main/java/shark/HeapObject.kt index 8551c988ab..a8fa60fc96 100644 --- a/shark/shark-graph/src/main/java/shark/HeapObject.kt +++ b/shark/shark-graph/src/main/java/shark/HeapObject.kt @@ -623,7 +623,7 @@ sealed class HeapObject { * The name of the class of this array, identical to [Class.getName]. */ val arrayClassName: String - get() = "${primitiveType.name.toLowerCase(Locale.US)}[]" + get() = "${primitiveType.name.lowercase(Locale.US)}[]" /** * The class of this array. @@ -651,7 +651,7 @@ sealed class HeapObject { companion object { internal val primitiveTypesByPrimitiveArrayClassName = - PrimitiveType.values().associateBy { "${it.name.toLowerCase(Locale.US)}[]" } + PrimitiveType.values().associateBy { "${it.name.lowercase(Locale.US)}[]" } private val primitiveWrapperClassNames = setOf( Boolean::class.javaObjectType.name, Char::class.javaObjectType.name, diff --git a/shark/shark-hprof/build.gradle.kts b/shark/shark-hprof/build.gradle.kts index 765ce9f8c4..544612aa01 100644 --- a/shark/shark-hprof/build.gradle.kts +++ b/shark/shark-hprof/build.gradle.kts @@ -14,12 +14,9 @@ dependencies { implementation(libs.kotlin.stdlib) // compileOnly ensures this dependency is not exposed through this artifact's pom.xml in Maven Central. // Okio is a required dependency, but we're making it required on the "shark" artifact which is the main artifact that - // should generally be used. The shark artifact depends on Okio 2.x (ensure compatibility with modern Okio). Depending on 1.x here - // enables us to ensure binary compatibility with Okio 1.x and allow us to use the deprecated (error level) Okio APIs to keep that - // compatibility. - // See https://github.com/square/leakcanary/issues/1624 - compileOnly(libs.okio1) - testImplementation(libs.okio1) + // should generally be used. The shark artifact depends on Okio 2.x (ensure compatibility with modern Okio). + compileOnly(libs.okio2) + testImplementation(libs.okio2) testImplementation(libs.assertjCore) testImplementation(libs.junit) diff --git a/shark/shark-hprof/src/main/java/shark/FileSourceProvider.kt b/shark/shark-hprof/src/main/java/shark/FileSourceProvider.kt index f558c202c7..0d047e0a61 100644 --- a/shark/shark-hprof/src/main/java/shark/FileSourceProvider.kt +++ b/shark/shark-hprof/src/main/java/shark/FileSourceProvider.kt @@ -5,10 +5,11 @@ import java.io.RandomAccessFile import kotlin.math.min import okio.Buffer import okio.BufferedSource -import okio.Okio +import okio.buffer +import okio.source class FileSourceProvider(private val file: File) : DualSourceProvider { - override fun openStreamingSource(): BufferedSource = Okio.buffer(Okio.source(file.inputStream())) + override fun openStreamingSource(): BufferedSource = file.inputStream().source().buffer() override fun openRandomAccessSource(): RandomAccessSource { diff --git a/shark/shark-hprof/src/main/java/shark/HprofHeader.kt b/shark/shark-hprof/src/main/java/shark/HprofHeader.kt index 56d531f84b..ed1704961a 100644 --- a/shark/shark-hprof/src/main/java/shark/HprofHeader.kt +++ b/shark/shark-hprof/src/main/java/shark/HprofHeader.kt @@ -1,7 +1,8 @@ package shark import okio.BufferedSource -import okio.Okio +import okio.buffer +import okio.source import java.io.File /** @@ -37,7 +38,7 @@ data class HprofHeader( if (fileLength == 0L) { throw IllegalArgumentException("Hprof file is 0 byte length") } - return Okio.buffer(Okio.source(hprofFile.inputStream())).use { + return hprofFile.inputStream().source().buffer().use { parseHeaderOf(it) } } diff --git a/shark/shark-hprof/src/main/java/shark/HprofPrimitiveArrayStripper.kt b/shark/shark-hprof/src/main/java/shark/HprofPrimitiveArrayStripper.kt index 1e0b69188d..500cb989fc 100644 --- a/shark/shark-hprof/src/main/java/shark/HprofPrimitiveArrayStripper.kt +++ b/shark/shark-hprof/src/main/java/shark/HprofPrimitiveArrayStripper.kt @@ -1,7 +1,8 @@ package shark import okio.BufferedSink -import okio.Okio +import okio.buffer +import okio.sink import shark.HprofRecord.HeapDumpEndRecord import shark.HprofRecord.HeapDumpRecord.ObjectRecord.PrimitiveArrayDumpRecord.BooleanArrayDump import shark.HprofRecord.HeapDumpRecord.ObjectRecord.PrimitiveArrayDumpRecord.ByteArrayDump @@ -38,7 +39,7 @@ class HprofPrimitiveArrayStripper { ): File { stripPrimitiveArrays( hprofSourceProvider = FileSourceProvider(inputHprofFile), - hprofSink = Okio.buffer(Okio.sink(outputHprofFile.outputStream())) + hprofSink = outputHprofFile.outputStream().sink().buffer() ) return outputHprofFile } diff --git a/shark/shark-hprof/src/main/java/shark/HprofWriter.kt b/shark/shark-hprof/src/main/java/shark/HprofWriter.kt index ae3c1a8142..c24633198e 100644 --- a/shark/shark-hprof/src/main/java/shark/HprofWriter.kt +++ b/shark/shark-hprof/src/main/java/shark/HprofWriter.kt @@ -4,7 +4,8 @@ import java.io.Closeable import java.io.File import okio.Buffer import okio.BufferedSink -import okio.Okio +import okio.buffer +import okio.sink import shark.GcRoot.Debugger import shark.GcRoot.Finalizing import shark.GcRoot.InternedString @@ -422,13 +423,13 @@ class HprofWriter private constructor( ) { flushHeapBuffer() workBuffer.block() - writeTagHeader(tag, workBuffer.size()) + writeTagHeader(tag, workBuffer.size) writeAll(workBuffer) } private fun BufferedSink.flushHeapBuffer() { - if (workBuffer.size() > 0) { - writeTagHeader(HprofRecordTag.HEAP_DUMP.tag, workBuffer.size()) + if (workBuffer.size > 0) { + writeTagHeader(HprofRecordTag.HEAP_DUMP.tag, workBuffer.size) writeAll(workBuffer) writeTagHeader(HprofRecordTag.HEAP_DUMP_END.tag, 0) } @@ -460,7 +461,7 @@ class HprofWriter private constructor( hprofFile: File, hprofHeader: HprofHeader = HprofHeader() ): HprofWriter { - return openWriterFor(Okio.buffer(Okio.sink(hprofFile.outputStream())), hprofHeader) + return openWriterFor(hprofFile.outputStream().sink().buffer(), hprofHeader) } fun openWriterFor( diff --git a/shark/shark-hprof/src/main/java/shark/RandomAccessHprofReader.kt b/shark/shark-hprof/src/main/java/shark/RandomAccessHprofReader.kt index 46402e7d37..4f1889c748 100644 --- a/shark/shark-hprof/src/main/java/shark/RandomAccessHprofReader.kt +++ b/shark/shark-hprof/src/main/java/shark/RandomAccessHprofReader.kt @@ -41,8 +41,8 @@ class RandomAccessHprofReader private constructor( mutableByteCount -= bytesRead } return withRecordReader(reader).apply { - check(buffer.size() == 0L) { - "Buffer not fully consumed: ${buffer.size()} bytes left" + check(buffer.size == 0L) { + "Buffer not fully consumed: ${buffer.size} bytes left" } } } @@ -69,4 +69,4 @@ class RandomAccessHprofReader private constructor( return RandomAccessHprofReader(hprofSourceProvider.openRandomAccessSource(), hprofHeader) } } -} \ No newline at end of file +} diff --git a/shark/shark-hprof/src/main/java/shark/RandomAccessSource.kt b/shark/shark-hprof/src/main/java/shark/RandomAccessSource.kt index c25001bc90..f5eae0f85f 100644 --- a/shark/shark-hprof/src/main/java/shark/RandomAccessSource.kt +++ b/shark/shark-hprof/src/main/java/shark/RandomAccessSource.kt @@ -2,9 +2,9 @@ package shark import okio.Buffer import okio.BufferedSource -import okio.Okio import okio.Source import okio.Timeout +import okio.buffer import java.io.Closeable import java.io.IOException @@ -17,7 +17,7 @@ interface RandomAccessSource : Closeable { ): Long fun asStreamingSource(): BufferedSource { - return Okio.buffer(object : Source { + return (object : Source { var position = 0L override fun timeout() = Timeout.NONE @@ -40,6 +40,6 @@ interface RandomAccessSource : Closeable { position += bytesRead return bytesRead } - }) + }).buffer() } } diff --git a/shark/shark-hprof/src/main/java/shark/ThrowingCancelableFileSourceProvider.kt b/shark/shark-hprof/src/main/java/shark/ThrowingCancelableFileSourceProvider.kt index 3f40c68aba..a350ee10ea 100644 --- a/shark/shark-hprof/src/main/java/shark/ThrowingCancelableFileSourceProvider.kt +++ b/shark/shark-hprof/src/main/java/shark/ThrowingCancelableFileSourceProvider.kt @@ -6,6 +6,8 @@ import okio.Buffer import okio.BufferedSource import okio.Okio import okio.Source +import okio.buffer +import okio.source /** * A [DualSourceProvider] that invokes [throwIfCanceled] before every read, allowing @@ -17,8 +19,8 @@ class ThrowingCancelableFileSourceProvider( ) : DualSourceProvider { override fun openStreamingSource(): BufferedSource { - val realSource = Okio.source(file.inputStream()) - return Okio.buffer(object : Source by realSource { + val realSource = file.inputStream().source() + return (object : Source by realSource { override fun read( sink: Buffer, byteCount: Long @@ -26,7 +28,7 @@ class ThrowingCancelableFileSourceProvider( throwIfCanceled.run() return realSource.read(sink, byteCount) } - }) + }).buffer() } override fun openRandomAccessSource(): RandomAccessSource { diff --git a/shark/shark/src/main/java/shark/LeakTraceObject.kt b/shark/shark/src/main/java/shark/LeakTraceObject.kt index e9c2b7a5a9..5c24ca718c 100644 --- a/shark/shark/src/main/java/shark/LeakTraceObject.kt +++ b/shark/shark/src/main/java/shark/LeakTraceObject.kt @@ -47,7 +47,7 @@ data class LeakTraceObject( val classSimpleName: String get() = className.lastSegment('.') val typeName - get() = type.name.toLowerCase(Locale.US) + get() = type.name.lowercase(Locale.US) override fun toString(): String { val firstLinePrefix = "" @@ -113,4 +113,4 @@ data class LeakTraceObject( return String.format("%.1f %sB", bytes / unit.toDouble().pow(exp.toDouble()), pre) } } -} \ No newline at end of file +}