From 61e4f1665221626cfd31a5826bff527ef7ce5719 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 15 Mar 2018 08:25:43 +0900 Subject: ObjectIdSerializer: Support serialization of known non-null ObjectId The implementation of ObjectIdSerializer, added in change I7599cf8bd, is not equivalent to the original implementation in Gerrit [1]. The Gerrit implementation provides separate methods to (de)serialize instances of ObjectId that are known to be non-null. In these methods, no "marker" is written to the stream. Replacing Gerrit's implementation with ObjectIdSerializer [2] broke persistent caches because it started writing markers where they were not expected [3]. Since ObjectIdSerializer is included in JGit 4.11 we can't change the existing #write and #read methods. Keep those as-is, but extend the Javadoc to clarify that they support possibly null ObjectId instances. Add new methods #writeWithoutMarker and #readWithoutMarker to support the cases where the ObjectId is known to be non-null and the marker should not be written to the serialization stream. Also: - Replace the hard-coded `0` and `1` markers with constants that can be linked from the Javadocs. - Include the marker value in the "Invalid flag before ObjectId" exception message. [1] https://gerrit-review.googlesource.com/c/gerrit/+/9792 [2] https://gerrit-review.googlesource.com/c/gerrit/+/165851 [3] https://gerrit-review.googlesource.com/c/gerrit/+/165952 Change-Id: Iaf84c3ec32ecf83efffb306fdb4940cc85740f3f Signed-off-by: David Pursehouse --- .../tst/org/eclipse/jgit/lib/ObjectIdSerializerTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'org.eclipse.jgit.test/tst') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdSerializerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdSerializerTest.java index 24bc40eee8..d98b792d75 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdSerializerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdSerializerTest.java @@ -79,10 +79,18 @@ public class ObjectIdSerializerTest { throws Exception { File file = File.createTempFile("ObjectIdSerializerTest_", ""); try (OutputStream out = new FileOutputStream(file)) { - ObjectIdSerializer.write(out, objectId); + if (objectId == null) { + ObjectIdSerializer.write(out, objectId); + } else { + ObjectIdSerializer.writeWithoutMarker(out, objectId); + } } try (InputStream in = new FileInputStream(file)) { - return ObjectIdSerializer.read(in); + if (objectId == null) { + return ObjectIdSerializer.read(in); + } else { + return ObjectIdSerializer.readWithoutMarker(in); + } } } } -- cgit v1.2.3