From 15a11fa9789d2b8286f879b40430ee5d68631e5f Mon Sep 17 00:00:00 2001 From: Justin Fiedler Date: Mon, 4 Mar 2024 09:21:25 -0800 Subject: [PATCH] fix: catch potential internal AssertionError from Properties.save() in Android 8 --- .../main/java/com/amplitude/id/utilities/PropertiesFile.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/id/src/main/java/com/amplitude/id/utilities/PropertiesFile.kt b/id/src/main/java/com/amplitude/id/utilities/PropertiesFile.kt index 321bd58f..88c5d2b7 100644 --- a/id/src/main/java/com/amplitude/id/utilities/PropertiesFile.kt +++ b/id/src/main/java/com/amplitude/id/utilities/PropertiesFile.kt @@ -22,7 +22,7 @@ class PropertiesFile(directory: File, key: String, prefix: String, logger: Logge underlyingProperties.load(it) } return - } catch (e: Exception) { + } catch (e: Throwable) { propertiesFile.delete() logger?.error("Failed to load property file with path ${propertiesFile.absolutePath}, error stacktrace: ${e.stackTraceToString()}") } @@ -36,7 +36,9 @@ class PropertiesFile(directory: File, key: String, prefix: String, logger: Logge FileOutputStream(propertiesFile).use { underlyingProperties.store(it, null) } - } catch (e: Exception) { + } catch (e: Throwable) { + // Note: we need to catch Throwable to handle both Exceptions and Errors + // Properties.store has an error in Android 8 that throws a AssertionError (vs Exception) logger?.error("Failed to save property file with path ${propertiesFile.absolutePath}, error stacktrace: ${e.stackTraceToString()}") } }