Skip to content

Commit

Permalink
Merge pull request #269 from ajkannan/nonnull-projID-namespace
Browse files Browse the repository at this point in the history
Don't allow user to set project id or namespace to null
  • Loading branch information
aozarov committed Oct 16, 2015
2 parents af6ab8f + a98d096 commit 8245607
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ protected B self() {
}

public B projectId(String projectId) {
this.projectId = projectId;
this.projectId =
checkNotNull(projectId, "Project ID cannot be set to null. Leave unset for default.");
return self();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.gcloud.datastore;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;

/**
Expand All @@ -29,14 +28,14 @@ public final class KeyFactory extends BaseKey.Builder<KeyFactory> {
private final String ns;

public KeyFactory(String projectId) {
this(projectId, null);
this(projectId, "");
}

public KeyFactory(String projectId, String namespace) {
super(projectId);
namespace(namespace);
this.pi = projectId;
this.ns = MoreObjects.firstNonNull(namespace, "");
this.ns = namespace;
}

public IncompleteKey newKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ static String validateDatabase(String projectId) {
}

static String validateNamespace(String namespace) {
if (Strings.isNullOrEmpty(namespace)) {
return "";
}
checkArgument(namespace != null, "Namespace cannot be null. Leave unset for default.");
checkArgument(namespace.length() <= MAX_NAMESPACE_LENGTH,
"namespace must not contain more than 100 characters");
checkArgument(NAMESPACE_PATTERN.matcher(namespace).matches(),
Expand Down

0 comments on commit 8245607

Please sign in to comment.