From 5528f4d93a31e22e146585c115360332dd6a0923 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Ricau Date: Thu, 10 Nov 2022 20:57:58 -0800 Subject: [PATCH] Ignore failure to close file Fixes #2382 --- .../java/shark/ThrowingCancelableFileSourceProvider.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/shark-hprof/src/main/java/shark/ThrowingCancelableFileSourceProvider.kt b/shark-hprof/src/main/java/shark/ThrowingCancelableFileSourceProvider.kt index 05a81049fd..3f40c68aba 100644 --- a/shark-hprof/src/main/java/shark/ThrowingCancelableFileSourceProvider.kt +++ b/shark-hprof/src/main/java/shark/ThrowingCancelableFileSourceProvider.kt @@ -1,6 +1,7 @@ package shark import java.io.File +import java.io.IOException import okio.Buffer import okio.BufferedSource import okio.Okio @@ -40,7 +41,13 @@ class ThrowingCancelableFileSourceProvider( return channel.transferTo(position, byteCount, sink) } - override fun close() = channel.close() + override fun close() { + try { + channel.close() + } catch (ignored: Throwable) { + SharkLog.d(ignored) { "Failed to close file, ignoring" } + } + } } } }