]> source.dussan.org Git - gitblit.git/commitdiff
Fix NPE
authorTom <tw201207@gmail.com>
Wed, 23 Nov 2016 17:30:48 +0000 (18:30 +0100)
committerFlorian Zschocke <2362065+flaix@users.noreply.github.com>
Wed, 3 Nov 2021 19:37:06 +0000 (20:37 +0100)
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

index 86d98474248e96426496dfc154fa2f59528296e5..43517180cf84b69573414fee91d5586582870128 100644 (file)
@@ -59,9 +59,9 @@ public class RefModel implements Serializable, Comparable<RefModel> {
                this.reference = ref;\r
                this.displayName = displayName;\r
                this.date = internalGetDate(refObject);\r
-               this.name = (ref != null) ? ref.getName() : displayName;\r
+               this.name = ref != null ? ref.getName() : displayName;\r
                this.type = internalGetReferencedObjectType(refObject);\r
-               this.objectId = internalGetObjectId(reference);\r
+               this.objectId = ref != null ? ref.getObjectId() : ObjectId.zeroId();\r
                this.id = this.objectId.getName();\r
                this.referencedObjectId = internalGetReferencedObjectId(refObject);\r
                this.referencedId = this.referencedObjectId.getName();\r
@@ -163,10 +163,6 @@ public class RefModel implements Serializable, Comparable<RefModel> {
                return person;\r
        }\r
 \r
-       private ObjectId internalGetObjectId(Ref reference) {\r
-               return reference.getObjectId();\r
-       }\r
-\r
        public ObjectId getObjectId() {\r
                if (objectId == null) {\r
                        objectId = ObjectId.fromString(id);\r
@@ -178,7 +174,7 @@ public class RefModel implements Serializable, Comparable<RefModel> {
                if (referencedObject instanceof RevTag) {\r
                        return !getReferencedObjectId().equals(getObjectId());\r
                }\r
-               return reference.getPeeledObjectId() != null;\r
+               return reference != null && reference.getPeeledObjectId() != null;\r
        }\r
 \r
        public boolean isAnnotatedTag() {\r