Don't rely on default field values, when VanillaChronicleMap instance is unsafe.allocateInstance()-ed for deserialization

This commit is contained in:
leventov
2015-11-27 15:25:13 +03:00
parent 4faefe8ca9
commit 1f3fc3f785
@@ -74,7 +74,7 @@ public abstract class VanillaChronicleHash<K,
/////////////////////////////////////////////////
// If the hash was created in the first place, or read from disk
public transient boolean createdOrInMemory = false;
public transient boolean createdOrInMemory;
/////////////////////////////////////////////////
// Key Data model
@@ -152,18 +152,17 @@ public abstract class VanillaChronicleHash<K,
public transient CompactOffHeapLinearHashTable hashLookup;
protected transient volatile boolean closed = false;
protected transient volatile boolean closed;
private transient VanillaGlobalMutableState globalMutableState;
public VanillaChronicleHash(ChronicleMapBuilder<K, ?> builder) {
createdOrInMemory = true;
closed = false;
// Version
dataFileVersion = BuildVersion.version();
// Because we are in constructor. If the Hash loaded from persistence file, deserialization
// bypasses the constructor and createdOrInMemory = false
this.createdOrInMemory = true;
@SuppressWarnings("deprecation")
ChronicleHashBuilderPrivateAPI<K> privateAPI = builder.privateAPI();
@@ -225,6 +224,13 @@ public abstract class VanillaChronicleHash<K,
}
protected void readMarshallableFields(@NotNull WireIn wireIn) throws IORuntimeException {
// Previously assignment of these values was done in default field initializers, but
// with Wire serialization VanillaChronicleMap instance is created with
// unsafe.allocateInstance(), that doesn't guarantee (?) to initialize fields with default
// values (false for boolean)
createdOrInMemory = false;
closed = false;
dataFileVersion = wireIn.read(() -> "dataFileVersion").text();
keyClass = wireIn.read(() -> "keyClass").typeLiteral();