Skip to content

Commit 9142f1f

Browse files
tomaswolfflaix
authored andcommitted
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.
1 parent 560f2e3 commit 9142f1f

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/main/java/com/gitblit/models/RefModel.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public RefModel(String displayName, Ref ref, RevObject refObject) {
5959
this.reference = ref;
6060
this.displayName = displayName;
6161
this.date = internalGetDate(refObject);
62-
this.name = (ref != null) ? ref.getName() : displayName;
62+
this.name = ref != null ? ref.getName() : displayName;
6363
this.type = internalGetReferencedObjectType(refObject);
64-
this.objectId = internalGetObjectId(reference);
64+
this.objectId = ref != null ? ref.getObjectId() : ObjectId.zeroId();
6565
this.id = this.objectId.getName();
6666
this.referencedObjectId = internalGetReferencedObjectId(refObject);
6767
this.referencedId = this.referencedObjectId.getName();
@@ -163,10 +163,6 @@ public PersonIdent getAuthorIdent() {
163163
return person;
164164
}
165165

166-
private ObjectId internalGetObjectId(Ref reference) {
167-
return reference.getObjectId();
168-
}
169-
170166
public ObjectId getObjectId() {
171167
if (objectId == null) {
172168
objectId = ObjectId.fromString(id);
@@ -178,7 +174,7 @@ private boolean internalIsAnnotatedTag(Ref reference, RevObject referencedObject
178174
if (referencedObject instanceof RevTag) {
179175
return !getReferencedObjectId().equals(getObjectId());
180176
}
181-
return reference.getPeeledObjectId() != null;
177+
return reference != null && reference.getPeeledObjectId() != null;
182178
}
183179

184180
public boolean isAnnotatedTag() {

0 commit comments

Comments
 (0)