Skip to content

Commit 93372fe

Browse files
committed
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 57571b1 commit 93372fe

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

docu/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ with full SSO through Gerrit.
55

66
* License: [Apache Public License 2.0](http://www.apache.org/licenses/LICENSE-2.0)
77
* [Home page](https://github.com/tomaswolf/gerrit-gitblit-plugin)
8-
* Installed plugin version: <em id='gerrit-gitblit-current-version'>2.12.171.5-SNAPSHOT</em> &mdash; <a id='gerrit-gitblit-version-check' style='display:none;' href='#'>Check for updates</a>
8+
* Installed plugin version: <em id='gerrit-gitblit-current-version'>2.12.171.6-SNAPSHOT</em> &mdash; <a id='gerrit-gitblit-version-check' style='display:none;' href='#'>Check for updates</a>
99

1010
For a list of contributors, see at [GitHub](https://github.com/tomaswolf/gerrit-gitblit-plugin/graphs/contributors).
1111

@@ -111,6 +111,6 @@ Report bugs or make feature requests at the [GitHub issue tracker](https://githu
111111

112112
<hr style="color: #C0C0C0; background-color: #C0C0C0; border-color: #C0C0C0; height: 2px;" />
113113
<div style="float:right;">
114-
<a href="https://github.com/tomaswolf/gerrit-gitblit-plugin" target="_blank">GitBlit plugin 2.12.171.5-SNAPSHOT</a>
114+
<a href="https://github.com/tomaswolf/gerrit-gitblit-plugin" target="_blank">GitBlit plugin 2.12.171.6-SNAPSHOT</a>
115115
</div>
116116
<script type="text/javascript" src="version_check.js"></script>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020
<artifactId>gitblit-plugin</artifactId>
2121
<description>GitBlit for Gerrit integrated as a plugin</description>
2222
<name>Gerrit - GitBlit Plugin</name>
23-
<version>2.12.171.5-SNAPSHOT</version><!-- Gerrit API version followed by collapsed GitBlit version, followed by plugin version -->
23+
<version>2.12.171.6-SNAPSHOT</version><!-- Gerrit API version followed by collapsed GitBlit version, followed by plugin version -->
2424
<licenses>
2525
<license>
2626
<name>Apache License 2.0</name>

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)