From 9142f1f74d5ab60335eb9f7d38b946c75f109460 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 23 Nov 2016 18:30:48 +0100 Subject: [PATCH] Fix NPE Although it seems strange to have a RefModel with a referenced object but a null Ref, Gitblit uses such RefModels for instance in JGitUtils.getNotesOnCommit(). Be careful to do something sensible when that Ref is null. --- src/main/java/com/gitblit/models/RefModel.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/gitblit/models/RefModel.java b/src/main/java/com/gitblit/models/RefModel.java index 86d98474..43517180 100644 --- a/src/main/java/com/gitblit/models/RefModel.java +++ b/src/main/java/com/gitblit/models/RefModel.java @@ -59,9 +59,9 @@ public class RefModel implements Serializable, Comparable { this.reference = ref; this.displayName = displayName; this.date = internalGetDate(refObject); - this.name = (ref != null) ? ref.getName() : displayName; + this.name = ref != null ? ref.getName() : displayName; this.type = internalGetReferencedObjectType(refObject); - this.objectId = internalGetObjectId(reference); + this.objectId = ref != null ? ref.getObjectId() : ObjectId.zeroId(); this.id = this.objectId.getName(); this.referencedObjectId = internalGetReferencedObjectId(refObject); this.referencedId = this.referencedObjectId.getName(); @@ -163,10 +163,6 @@ public class RefModel implements Serializable, Comparable { return person; } - private ObjectId internalGetObjectId(Ref reference) { - return reference.getObjectId(); - } - public ObjectId getObjectId() { if (objectId == null) { objectId = ObjectId.fromString(id); @@ -178,7 +174,7 @@ public class RefModel implements Serializable, Comparable { if (referencedObject instanceof RevTag) { return !getReferencedObjectId().equals(getObjectId()); } - return reference.getPeeledObjectId() != null; + return reference != null && reference.getPeeledObjectId() != null; } public boolean isAnnotatedTag() { -- 2.39.5