Skip to content

Commit d65621f

Browse files
hein-2improveitjetersen
authored andcommitted
Fix NullPointerException and Concurrency Issues (jenkinsci#244)
1 parent e8c8a3c commit d65621f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/server/client/branch/BitbucketServerBranch.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public String getName() {
6363
return displayId;
6464
}
6565

66-
public long getTimestamp() {
66+
public synchronized long getTimestamp() {
6767
return timestamp();
6868
}
6969

@@ -88,24 +88,24 @@ public void setRawNode(String latestCommit) {
8888
this.latestCommit = latestCommit;
8989
}
9090

91-
public void setTimestamp(long timestamp) {
91+
public synchronized void setTimestamp(long timestamp) {
9292
this.timestamp = timestamp;
9393
}
9494

9595
@Restricted(NoExternalUse.class)
96-
public void setCommitClosure(Callable<BitbucketCommit> commitClosure) {
96+
public synchronized void setCommitClosure(Callable<BitbucketCommit> commitClosure) {
9797
this.commitClosure = commitClosure;
9898
}
9999

100-
private long timestamp() {
100+
private synchronized long timestamp() {
101101
if (timestamp == null) {
102102
if (commitClosure == null) {
103103
timestamp = 0L;
104104
} else {
105105
initHeadCommitInfo();
106106
}
107107
}
108-
return timestamp;
108+
return timestamp == null ? 0L : timestamp;
109109
}
110110

111111
@Override
@@ -132,12 +132,10 @@ public void setAuthor(String author) {
132132
this.author = author;
133133
}
134134

135-
private void initHeadCommitInfo() {
135+
private synchronized void initHeadCommitInfo() {
136136
if (callableInitialised || commitClosure == null) {
137137
return;
138138
}
139-
140-
callableInitialised = true;
141139
try {
142140
BitbucketCommit commit = commitClosure.call();
143141

@@ -148,6 +146,9 @@ private void initHeadCommitInfo() {
148146
LOGGER.log(Level.FINER, "Could not determine head commit details", e);
149147
// fallback on default values
150148
this.timestamp = 0L;
149+
this.message = "Unknown";
150+
this.author = "Unknown";
151151
}
152+
callableInitialised = true;
152153
}
153154
}

0 commit comments

Comments
 (0)