Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-74777] Improve locking around jenkins.branch.MultiBranchProject#getProjectFactory #494

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
/**
* 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 @@
* @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