aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabio Ponciroli <ponch78@gmail.com>2023-12-06 14:38:21 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2023-12-09 14:28:17 +0000
commite712b4716cbbe08abc7e7f79c5b4a59e51a0b900 (patch)
treecbe09b731e9ded4cd8f7e86dda3c240101b1703a
parentb6098c549d1ad052917a3515d2d1c19c03b7bce9 (diff)
downloadjgit-e712b4716cbbe08abc7e7f79c5b4a59e51a0b900.tar.gz
jgit-e712b4716cbbe08abc7e7f79c5b4a59e51a0b900.zip
Make sure ref to prune is in packed refs
RefDirectory:pack might raise an NPE when deleting loose refs as final part of the RefDirectory.pack(). This is what the code does: 1) packed ref update: update the list of refs which will be persisted in packed-refs 2) persit packed-refs: flush on file the refs computed in #1 3) prune loose refs: prune loose refs that have been packed in #2 The code correctly locks the packed-refs file during phases 1 to 3. However, it makes the wrong assumption of considering the loose refs set as immutable between phases 1 and 3. The number and values of loose refs on the filesystem can mutate at any time whilst the RefDirectory.pack() is in progress. Assuming the contrary can lead to an NPE when retrieving refs from the mutable loose refs list during phase #3. Make sure that the ref is not null before dereferencing its object-id value. Bug: jgit-4 Change-Id: I2cd01f8a880f3c6561ad978a389ec2db45b6018b
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java2
1 files changed, 1 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
index f0676d9bec..9f31e688c3 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
@@ -813,7 +813,7 @@ public class RefDirectory extends RefDatabase {
}
Ref packedRef = newPacked.get(refName);
ObjectId clr_oid = currentLooseRef.getObjectId();
- if (clr_oid != null
+ if (clr_oid != null && packedRef != null
&& clr_oid.equals(packedRef.getObjectId())) {
RefList<LooseRef> curLoose, newLoose;
do {