From 4bb87a957fb252b2b1512a0aec4344f6c91fa33d Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Sun, 30 Jan 2022 22:15:14 +0100 Subject: [PATCH] ObjectWalk: close ObjectReader on close() if needed If the walk is created via ObjectWalk(Repository), it creates a new ObjectReader. This reader was closed only on dispose(). If such an ObjectWalk was used in a try-with-resource statement the reader might not get closed. Bug: 578458 Change-Id: I1be31829dc466530f23006a53c29b657fd5fb410 Signed-off-by: Thomas Wolf --- .../src/org/eclipse/jgit/revwalk/ObjectWalk.java | 10 +++++++--- .../src/org/eclipse/jgit/revwalk/RevWalk.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java index e6f9580bf7..4e48a5c328 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, Shawn O. Pearce and others + * Copyright (C) 2008, 2022 Shawn O. Pearce and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -139,7 +139,7 @@ public class ObjectWalk extends RevWalk { * the repository the walker will obtain data from. */ public ObjectWalk(Repository repo) { - this(repo.newObjectReader()); + this(repo.newObjectReader(), true); } /** @@ -151,7 +151,11 @@ public class ObjectWalk extends RevWalk { * required. */ public ObjectWalk(ObjectReader or) { - super(or); + this(or, false); + } + + private ObjectWalk(ObjectReader or, boolean closeReader) { + super(or, closeReader); setRetainBody(false); rootObjects = new ArrayList<>(); pendingObjects = new BlockObjQueue(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java index 8d571f5b14..a50eaf1a8a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java @@ -215,7 +215,7 @@ public class RevWalk implements Iterable, AutoCloseable { this(or, false); } - private RevWalk(ObjectReader or, boolean closeReader) { + RevWalk(ObjectReader or, boolean closeReader) { reader = or; idBuffer = new MutableObjectId(); objects = new ObjectIdOwnerMap<>(); -- 2.39.5