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

Make ContentContainer.contents thread-safe #437

Merged
merged 1 commit into from
Feb 1, 2023
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
20 changes: 14 additions & 6 deletions src/main/java/com/cloudbees/jenkins/support/SupportPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -568,13 +569,13 @@ private static List<Content> appendManifestContents(StringBuilder manifest,
errors.println();
}
}
return contentsContainer.contents;
return contentsContainer.getContents();

}

private static class ContentContainer extends Container {
private final List<Content> contents = new ArrayList<>();
private final Set<String> names = new TreeSet<>();
private final Set<String> names = new HashSet<>();

//The filter to return the names filtered
private final Optional<ContentFilter> maybeFilter;
Expand All @@ -583,24 +584,31 @@ private static class ContentContainer extends Container {
* We need the filter to be able to filter the contents written to the manifest
* @param maybeFilter filter to use when writing the name of the contents
*/
public ContentContainer(Optional<ContentFilter> maybeFilter) {
ContentContainer(Optional<ContentFilter> maybeFilter) {
this.maybeFilter = maybeFilter;
}

@Override
public void add(Content content) {
if (content != null) {
contents.add(content);
names.add(getNameFiltered(maybeFilter, content.getName(), content.getFilterableParameters()));
String name = getNameFiltered(maybeFilter, content.getName(), content.getFilterableParameters());
synchronized (this) {
contents.add(content);
names.add(name);
}
}
}

private Set<String> getLatestNames() {
synchronized Set<String> getLatestNames() {
Set<String> copy = new TreeSet<>(names);
names.clear();
return copy;
}

synchronized List<Content> getContents() {
return new ArrayList<>(contents);
}

}

public List<LogRecord> getAllLogRecords() {
Expand Down