Skip to content

Commit

Permalink
[JENKINS-74777] Improve locking around `jenkins.branch.MultiBranchPro…
Browse files Browse the repository at this point in the history
…ject#getProjectFactory` (#494)
  • Loading branch information
basil authored Nov 6, 2024
1 parent 20ee565 commit 4ba3da2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/jenkins/branch/MultiBranchProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public abstract class MultiBranchProject<P extends Job<P, R> & TopLevelItem,
/**
* The factory for building child job instances.
*/
private BranchProjectFactory<P, R> factory;
private volatile BranchProjectFactory<P, R> factory;

private transient String srcDigest, facDigest;

Expand Down Expand Up @@ -339,11 +339,19 @@ public String getSourcePronoun() {
* @return the {@link BranchProjectFactory}.
*/
@NonNull
public synchronized BranchProjectFactory<P, R> getProjectFactory() {
if (factory == null) {
setProjectFactory(newProjectFactory());
@SuppressFBWarnings(value = "UG_SYNC_SET_UNSYNC_GET", justification = "False positive: synchronization is handled via double-checked locking")
public BranchProjectFactory<P, R> getProjectFactory() {
BranchProjectFactory<P, R> value = factory;
if (value == null) {
synchronized (this) {
value = factory;
if (value == null) {

Check warning on line 348 in src/main/java/jenkins/branch/MultiBranchProject.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 348 is only partially covered, one branch is missing
value = newProjectFactory();
setProjectFactory(value);
}
}
}
return factory;
return value;
}

/**
Expand Down

0 comments on commit 4ba3da2

Please sign in to comment.