Repository navigation
bug: Updating to 4.3.1 causes existing databases to no open correctly #1162
Copy link
Copy link
Description
Activity
- changed the title
[-]Updating to 4.3.1 causes existing databases to no open correctly[/-][+]bug: Updating to 4.3.1 causes existing databases to no open correctly[/+]on Sep 23, 2025 I think this fixes the issue but it's probably worth adding a few more tests just to be sure:
Subject: [PATCH] fix(gh-1162): ensure NitriteId serialization is compatible with previous versions --- Index: nitrite/src/main/java/org/dizitart/no2/collection/NitriteId.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/NitriteId.java b/nitrite/src/main/java/org/dizitart/no2/collection/NitriteId.java --- a/nitrite/src/main/java/org/dizitart/no2/collection/NitriteId.java (revision a8d05e7251784114488f6030609ca95ad0138a2e) +++ b/nitrite/src/main/java/org/dizitart/no2/collection/NitriteId.java (date 1758645815272) @@ -17,7 +17,6 @@ package org.dizitart.no2.collection; import lombok.EqualsAndHashCode; -import lombok.Getter; import org.dizitart.no2.exceptions.InvalidIdException; import java.io.IOException; @@ -41,25 +40,25 @@ * @see NitriteCollection#getById(NitriteId) * @since 1.0 */ -@Getter @EqualsAndHashCode public final class NitriteId implements Comparable<NitriteId>, Serializable { private static final long serialVersionUID = 1477462375L; private static final SnowflakeIdGenerator generator = new SnowflakeIdGenerator(); /** The underlying value of the NitriteId. */ - private long idValue; + // WARNING: naming it idValue breaks java serialization for databases created with earlier version of nitrite + private long _idValue; private NitriteId() { - this.idValue = generator.getId(); + this._idValue = generator.getId(); } private NitriteId(String value) { - this.idValue = Long.parseLong(value); + this._idValue = Long.parseLong(value); } private NitriteId(long value) { - this.idValue = value; + this._idValue = value; } /** @@ -115,21 +114,25 @@ } } + public long getIdValue() { + return _idValue; + } + @Override public int compareTo(NitriteId other) { - return Long.compare(idValue, other.idValue); + return Long.compare(_idValue, other._idValue); } @Override public String toString() { - return ID_PREFIX + idValue + ID_SUFFIX; + return ID_PREFIX + _idValue + ID_SUFFIX; } private void writeObject(ObjectOutputStream stream) throws IOException { - stream.writeUTF(Long.toString(idValue)); + stream.writeUTF(Long.toString(_idValue)); } private void readObject(ObjectInputStream stream) throws IOException { - idValue = Long.parseLong(stream.readUTF()); + _idValue = Long.parseLong(stream.readUTF()); } }
Could you please raise a PR for this fix? I'll do a quick rollout if all check passed.
Could you please raise a PR for this fix? I'll do a quick rollout if all check passed.
--> #1164
I also ran the tests from my project against the version with the bugfix and everything looks good. Not sure if there are any edgecases you can think of that are also worth testing.
- added a commit that references this issue
on Sep 25, 2025
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
It seems like #1117 breaks support for databases created with
4.3.0- at least when working with repositories. The following exception is thrown:and the database is rolled back to an earlier version. In my case this was luckily caught in a test as it seems to result in a wipe of the collection in the database.
Reproducer: https://github.com/DarkAtra/nitrite-java/blob/v4.3.1-nitrite-id-issue/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/MyTest.kt#L75-L103