Skip to content

Commit

Permalink
Enforce that repository mapping is never null (it can be empty).
Browse files Browse the repository at this point in the history
RELNOTES: None
PiperOrigin-RevId: 202167782
  • Loading branch information
dkelmer authored and Copybara-Service committed Jun 26, 2018
1 parent f166d1c commit a19a56d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public static Label parseAbsolute(
boolean defaultToMain,
ImmutableMap<RepositoryName, RepositoryName> repositoryMapping)
throws LabelSyntaxException {
Preconditions.checkNotNull(repositoryMapping);
String repo = defaultToMain ? "@" : RepositoryName.DEFAULT_REPOSITORY;
int packageStartPos = absName.indexOf("//");
if (packageStartPos > 0) {
Expand Down Expand Up @@ -158,6 +159,7 @@ public static Label parseAbsolute(
private static RepositoryName getGlobalRepoName(
String repo, ImmutableMap<RepositoryName, RepositoryName> repositoryMapping)
throws LabelSyntaxException {
Preconditions.checkNotNull(repositoryMapping);
RepositoryName repoName = RepositoryName.create(repo);
return repositoryMapping.getOrDefault(repoName, repoName);
}
Expand Down Expand Up @@ -524,6 +526,7 @@ public Label getRelative(String relName) throws LabelSyntaxException {
public Label getRelativeWithRemapping(
String relName, ImmutableMap<RepositoryName, RepositoryName> repositoryMapping)
throws LabelSyntaxException {
Preconditions.checkNotNull(repositoryMapping);
if (relName.length() == 0) {
throw new LabelSyntaxException("empty package-relative label");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ protected void finishInit(Builder builder) {
this.posts = ImmutableList.copyOf(builder.posts);
this.registeredExecutionPlatforms = ImmutableList.copyOf(builder.registeredExecutionPlatforms);
this.registeredToolchains = ImmutableList.copyOf(builder.registeredToolchains);
this.repositoryMapping = builder.repositoryMapping;
this.repositoryMapping = Preconditions.checkNotNull(builder.repositoryMapping);
ImmutableMap.Builder<RepositoryName, ImmutableMap<RepositoryName, RepositoryName>>
repositoryMappingsBuilder = ImmutableMap.builder();
if (!builder.externalPackageRepositoryMappings.isEmpty() && !builder.isWorkspace()) {
Expand Down Expand Up @@ -929,7 +929,7 @@ public Builder addRepositoryMappings(Package aPackage) {
* package)
*/
Builder setRepositoryMapping(ImmutableMap<RepositoryName, RepositoryName> repositoryMapping) {
this.repositoryMapping = repositoryMapping;
this.repositoryMapping = Preconditions.checkNotNull(repositoryMapping);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class RepositoryMappingValue implements SkyValue {
private final ImmutableMap<RepositoryName, RepositoryName> repositoryMapping;

private RepositoryMappingValue(ImmutableMap<RepositoryName, RepositoryName> repositoryMapping) {
Preconditions.checkNotNull(repositoryMapping);
this.repositoryMapping = repositoryMapping;
}

Expand Down

0 comments on commit a19a56d

Please sign in to comment.