Skip to main content
diff options
authorDavid Pursehouse2018-03-14 23:25:43 +0000
committerDavid Pursehouse2018-03-15 00:39:43 +0000
commit61e4f1665221626cfd31a5826bff527ef7ce5719 (patch)
tree269068f34431b783de7e459513004a749d45fe2c /org.eclipse.jgit.test/tst
parentf389e18a2853d9f73336f4cf0e7ac2931dc4ce9b (diff)
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] [2] [3] Change-Id: Iaf84c3ec32ecf83efffb306fdb4940cc85740f3f Signed-off-by: David Pursehouse <>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
1 files changed, 10 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/
index 24bc40eee8..d98b792d75 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/
@@ -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;
+ if (objectId == null) {
+ return;
+ } else {
+ return ObjectIdSerializer.readWithoutMarker(in);
+ }

Back to the top