Skip to content

Commit 4ba3da2

Browse files
authored
[JENKINS-74777] Improve locking around jenkins.branch.MultiBranchProject#getProjectFactory (#494)
1 parent 20ee565 commit 4ba3da2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/main/java/jenkins/branch/MultiBranchProject.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public abstract class MultiBranchProject<P extends Job<P, R> & TopLevelItem,
160160
/**
161161
* The factory for building child job instances.
162162
*/
163-
private BranchProjectFactory<P, R> factory;
163+
private volatile BranchProjectFactory<P, R> factory;
164164

165165
private transient String srcDigest, facDigest;
166166

@@ -339,11 +339,19 @@ public String getSourcePronoun() {
339339
* @return the {@link BranchProjectFactory}.
340340
*/
341341
@NonNull
342-
public synchronized BranchProjectFactory<P, R> getProjectFactory() {
343-
if (factory == null) {
344-
setProjectFactory(newProjectFactory());
342+
@SuppressFBWarnings(value = "UG_SYNC_SET_UNSYNC_GET", justification = "False positive: synchronization is handled via double-checked locking")
343+
public BranchProjectFactory<P, R> getProjectFactory() {
344+
BranchProjectFactory<P, R> value = factory;
345+
if (value == null) {
346+
synchronized (this) {
347+
value = factory;
348+
if (value == null) {
349+
value = newProjectFactory();
350+
setProjectFactory(value);
351+
}
352+
}
345353
}
346-
return factory;
354+
return value;
347355
}
348356

349357
/**

0 commit comments

Comments
 (0)