Navigation Menu

Skip to content

Commit

Permalink
[FIX JENKINS-28290] prevent ArrayIndexOutOfBoundException
Browse files Browse the repository at this point in the history
parent may be null when shallow clone is used
  • Loading branch information
ndeloof committed May 18, 2015
1 parent b88b388 commit 11c38d3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/hudson/plugins/git/GitChangeSet.java
Expand Up @@ -13,6 +13,7 @@
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import javax.annotation.CheckForNull;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
Expand Down Expand Up @@ -101,10 +102,14 @@ private void parseCommit(List<String> lines) {
if( line.length() < 1)
continue;
if (line.startsWith("commit ")) {
this.id = line.split(" ")[1];
String[] split = line.split(" ");
if (split.length > 0) this.id = split[1];
else throw new IllegalArgumentException("Commit has no ID" + lines);
} else if (line.startsWith("tree ")) {
} else if (line.startsWith("parent ")) {
this.parentCommit = line.split(" ")[1];
String[] split = line.split(" ");
// parent may be null for initial commit or changelog computed from a shallow clone
if (split.length > 0) this.parentCommit = split[1];
} else if (line.startsWith(PREFIX_COMMITTER)) {
Matcher committerMatcher = COMMITTER_ENTRY.matcher(line);
if (committerMatcher.matches()
Expand Down Expand Up @@ -222,7 +227,8 @@ public void setParent(ChangeLogSet parent) {
super.setParent(parent);
}

public String getParentCommit() {
public @CheckForNull
String getParentCommit() {
return parentCommit;
}

Expand Down

0 comments on commit 11c38d3

Please sign in to comment.