From 4263c2da123d241a7d0fe11e777b7bc80dae4af7 Mon Sep 17 00:00:00 2001 From: James Moger Date: Tue, 8 Apr 2014 00:07:45 -0400 Subject: [PATCH] Fix intermittent NPE in getting commit date in RefModel --- releases.moxie | 1 + src/main/java/com/gitblit/models/RefModel.java | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/releases.moxie b/releases.moxie index ee125355..34e64887 100644 --- a/releases.moxie +++ b/releases.moxie @@ -11,6 +11,7 @@ r22: { security: ~ fixes: - Repository mailing lists could not be reset from the Edit Repository page (issue-399) + - Fix intermittent NPE in determining commit date in RefModel (issue-401) - Fix closing ticket on push by parsing commit messages for closes|fixes (issue-404) - Ensure the Lucene ticket index is updated on repository deletion. changes: diff --git a/src/main/java/com/gitblit/models/RefModel.java b/src/main/java/com/gitblit/models/RefModel.java index 6b031ed3..02ba1302 100644 --- a/src/main/java/com/gitblit/models/RefModel.java +++ b/src/main/java/com/gitblit/models/RefModel.java @@ -25,6 +25,8 @@ import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevObject; import org.eclipse.jgit.revwalk.RevTag; +import com.gitblit.utils.JGitUtils; + /** * RefModel is a serializable model class that represents a tag or branch and * includes the referenced object. @@ -50,11 +52,18 @@ public class RefModel implements Serializable, Comparable { if (referencedObject != null) { if (referencedObject instanceof RevTag) { RevTag tag = (RevTag) referencedObject; - if (tag.getTaggerIdent() != null) { - date = tag.getTaggerIdent().getWhen(); + PersonIdent tagger = tag.getTaggerIdent(); + if (tagger != null) { + date = tagger.getWhen(); } } else if (referencedObject instanceof RevCommit) { - date = ((RevCommit) referencedObject).getCommitterIdent().getWhen(); + RevCommit commit = (RevCommit) referencedObject; + PersonIdent committer = commit.getCommitterIdent(); + if (committer != null) { + date = committer.getWhen(); + } else { + date = JGitUtils.getCommitDate(commit); + } } } return date; -- 2.39.5