From c52f1e096fb052824b14a5a2db7fd66d078293fb Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 1 Mar 2016 15:23:47 +0100 Subject: [PATCH] Minor: a serialisation related fix and an additional explainer comment in SerializedBytes --- core/src/main/kotlin/core/serialization/Kryo.kt | 1 + core/src/main/kotlin/core/utilities/ProgressTracker.kt | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/main/kotlin/core/serialization/Kryo.kt b/core/src/main/kotlin/core/serialization/Kryo.kt index 3cc4924aa3..ff59a34767 100644 --- a/core/src/main/kotlin/core/serialization/Kryo.kt +++ b/core/src/main/kotlin/core/serialization/Kryo.kt @@ -68,6 +68,7 @@ val THREAD_LOCAL_KRYO = ThreadLocal.withInitial { createKryo() } * to get the original object back. */ class SerializedBytes(bits: ByteArray) : OpaqueBytes(bits) { + // It's OK to use lazy here because SerializedBytes is configured to use the ImmutableClassSerializer. val hash: SecureHash by lazy { bits.sha256() } fun writeToFile(path: Path) = Files.write(path, bits) diff --git a/core/src/main/kotlin/core/utilities/ProgressTracker.kt b/core/src/main/kotlin/core/utilities/ProgressTracker.kt index 7e66f3c8b6..1bf99c29f2 100644 --- a/core/src/main/kotlin/core/utilities/ProgressTracker.kt +++ b/core/src/main/kotlin/core/utilities/ProgressTracker.kt @@ -65,8 +65,13 @@ class ProgressTracker(vararg steps: Step) { override val label: String get() = currentLabel } - object UNSTARTED : Step("Unstarted") - object DONE : Step("Done") + // Sentinel objects. Overrides equals() to survive process restarts and serialization. + object UNSTARTED : Step("Unstarted") { + override fun equals(other: Any?) = other is UNSTARTED + } + object DONE : Step("Done") { + override fun equals(other: Any?) = other is DONE + } /** The steps in this tracker, same as the steps passed to the constructor but with UNSTARTED and DONE inserted. */ val steps = arrayOf(UNSTARTED, *steps, DONE)