Skip to content

Commit

Permalink
fix: catch potential internal AssertionError from Properties.save() i…
Browse files Browse the repository at this point in the history
…n Android 8
  • Loading branch information
justin-fiedler committed Mar 4, 2024
1 parent 048e462 commit 15a11fa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions id/src/main/java/com/amplitude/id/utilities/PropertiesFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()}")
}
Expand All @@ -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()}")
}
}
Expand Down

0 comments on commit 15a11fa

Please sign in to comment.