From 5f5d1aad933de703b768abb113ed1ddf1b04a3f0 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 14 Feb 2021 23:06:52 +0000 Subject: [PATCH] Fix divide by zero in CacheExporter Signed-off-by: Graham --- .../org/openrs2/archive/cache/CacheExporter.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt index 808f1732..fec8cfde 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt @@ -19,15 +19,27 @@ public class CacheExporter @Inject constructor( ) { public data class ArchiveStats(val indexes: Long, val validIndexes: Long) { public val allIndexesValid: Boolean = indexes == validIndexes - public val validIndexesFraction: Double = validIndexes.toDouble() / indexes + public val validIndexesFraction: Double = if (indexes == 0L) { + 1.0 + } else { + validIndexes.toDouble() / indexes + } } public data class GroupStats(val groups: Long, val validGroups: Long, val keys: Long, val validKeys: Long) { public val allGroupsValid: Boolean = groups == validGroups - public val validGroupsFraction: Double = validGroups.toDouble() / groups + public val validGroupsFraction: Double = if (groups == 0L) { + 1.0 + } else { + validGroups.toDouble() / groups + } public val allKeysValid: Boolean = keys == validKeys - public val validKeysFraction: Double = validKeys.toDouble() / keys + public val validKeysFraction: Double = if (keys == 0L) { + 1.0 + } else { + validKeys.toDouble() / keys + } } public data class Cache(