Skip to content

Commit

Permalink
Make RepositoriesMetaData contents unmodifiable (#30361)
Browse files Browse the repository at this point in the history
This commit makes the RepositoriesMetaData backing list no longer
modifiable.

Ref #30333
  • Loading branch information
hub-cap authored May 3, 2018
1 parent 09a6ba4 commit 5f8101a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;

Expand All @@ -51,7 +52,7 @@ public class RepositoriesMetaData extends AbstractNamedDiffable<Custom> implemen
* @param repositories list of repositories
*/
public RepositoriesMetaData(List<RepositoryMetaData> repositories) {
this.repositories = repositories;
this.repositories = Collections.unmodifiableList(repositories);
}

/**
Expand Down Expand Up @@ -107,7 +108,7 @@ public RepositoriesMetaData(StreamInput in) throws IOException {
for (int i = 0; i < repository.length; i++) {
repository[i] = new RepositoryMetaData(in);
}
this.repositories = Arrays.asList(repository);
this.repositories = Collections.unmodifiableList(Arrays.asList(repository));
}

public static NamedDiff<Custom> readDiffFrom(StreamInput in) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected Custom doParseInstance(XContentParser parser) throws IOException {
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
RepositoriesMetaData repositoriesMetaData = RepositoriesMetaData.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
List<RepositoryMetaData> repos = repositoriesMetaData.repositories();
List<RepositoryMetaData> repos = new ArrayList<>(repositoriesMetaData.repositories());
repos.sort(Comparator.comparing(RepositoryMetaData::name));
return new RepositoriesMetaData(repos);
}
Expand Down

0 comments on commit 5f8101a

Please sign in to comment.