From 3a1970c73c301d91008c20e632079f370943a3c5 Mon Sep 17 00:00:00 2001 From: f43nd1r Date: Fri, 1 Sep 2023 22:16:55 +0200 Subject: [PATCH] 100% safe pref access in limiter. Closes #1233, #1236 --- .../java/org/acra/startup/LimiterStartupProcessor.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/acra-limiter/src/main/java/org/acra/startup/LimiterStartupProcessor.kt b/acra-limiter/src/main/java/org/acra/startup/LimiterStartupProcessor.kt index 149a45c6ca..d3bb344194 100644 --- a/acra-limiter/src/main/java/org/acra/startup/LimiterStartupProcessor.kt +++ b/acra-limiter/src/main/java/org/acra/startup/LimiterStartupProcessor.kt @@ -40,9 +40,13 @@ class LimiterStartupProcessor : HasConfigPlugin(LimiterConfiguration::class.java if (limiterConfiguration.deleteReportsOnAppUpdate || limiterConfiguration.resetLimitsOnAppUpdate) { val prefs = SharedPreferencesFactory(context, config).create() val lastVersionNr = try { - prefs.getLong(ACRA.PREF_LAST_VERSION_NR, 0) - } catch (e: ClassCastException) { - prefs.getInt(ACRA.PREF_LAST_VERSION_NR, 0).toLong() + try { + prefs.getLong(ACRA.PREF_LAST_VERSION_NR, 0) + } catch (e: ClassCastException) { + prefs.getInt(ACRA.PREF_LAST_VERSION_NR, 0).toLong() + } + } catch (e: Exception) { + 0 } val appVersion = getAppVersion(context) if (appVersion > lastVersionNr) {