Skip to content

Commit

Permalink
fix: check for not null input for Id classes (#159)
Browse files Browse the repository at this point in the history
Fixes #145
  • Loading branch information
olavloite committed Apr 21, 2020
1 parent 63a6bd8 commit ecf5826
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
Expand Up @@ -30,8 +30,8 @@ public final class BackupId {
private final String backup;

BackupId(InstanceId instanceId, String backup) {
this.instanceId = instanceId;
this.backup = backup;
this.instanceId = Preconditions.checkNotNull(instanceId);
this.backup = Preconditions.checkNotNull(backup);
}

/** Returns the instance id for this backup. */
Expand Down Expand Up @@ -81,6 +81,7 @@ public String toString() {
* @throws IllegalArgumentException if {@code name} does not conform to the expected pattern
*/
static BackupId of(String name) {
Preconditions.checkNotNull(name);
Map<String, String> parts = NAME_TEMPLATE.match(name);
Preconditions.checkArgument(
parts != null, "Name should conform to pattern %s: %s", NAME_TEMPLATE, name);
Expand Down
Expand Up @@ -31,8 +31,8 @@ public final class DatabaseId {
private final String database;

DatabaseId(InstanceId instanceId, String database) {
this.instanceId = instanceId;
this.database = database;
this.instanceId = Preconditions.checkNotNull(instanceId);
this.database = Preconditions.checkNotNull(database);
}

/** Returns the instance id for this databse. */
Expand Down Expand Up @@ -82,6 +82,7 @@ public String toString() {
* @throws IllegalArgumentException if {@code name} does not conform to the expected pattern
*/
static DatabaseId of(String name) {
Preconditions.checkNotNull(name);
Map<String, String> parts = NAME_TEMPLATE.match(name);
Preconditions.checkArgument(
parts != null, "Name should conform to pattern %s: %s", NAME_TEMPLATE, name);
Expand Down
Expand Up @@ -30,8 +30,8 @@ public final class InstanceConfigId {
private final String instanceConfig;

InstanceConfigId(String project, String instanceConfig) {
this.project = project;
this.instanceConfig = instanceConfig;
this.project = Preconditions.checkNotNull(project);
this.instanceConfig = Preconditions.checkNotNull(instanceConfig);
}

/** Returns project of this instane config. */
Expand Down Expand Up @@ -80,6 +80,7 @@ public String toString() {
* pattern.
*/
static InstanceConfigId of(String name) {
Preconditions.checkNotNull(name);
Map<String, String> parts = NAME_TEMPLATE.match(name);
Preconditions.checkArgument(
parts != null, "Name should confirm to pattern %s: %s", NAME_TEMPLATE, name);
Expand Down
Expand Up @@ -30,8 +30,8 @@ public final class InstanceId {
private final String instance;

InstanceId(String project, String instance) {
this.project = project;
this.instance = instance;
this.project = Preconditions.checkNotNull(project);
this.instance = Preconditions.checkNotNull(instance);
}

/** Returns the instance ID. */
Expand Down Expand Up @@ -79,6 +79,7 @@ public String toString() {
* pattern.
*/
static InstanceId of(String name) {
Preconditions.checkNotNull(name);
Map<String, String> parts = NAME_TEMPLATE.match(name);
Preconditions.checkArgument(
parts != null, "Name should conform to pattern %s: %s", NAME_TEMPLATE, name);
Expand Down
Expand Up @@ -44,11 +44,12 @@ static class SessionId {
private final String name;

private SessionId(DatabaseId db, String name) {
this.db = db;
this.name = name;
this.db = Preconditions.checkNotNull(db);
this.name = Preconditions.checkNotNull(name);
}

static SessionId of(String name) {
Preconditions.checkNotNull(name);
Map<String, String> parts = NAME_TEMPLATE.match(name);
Preconditions.checkArgument(
parts != null, "Name should conform to pattern %s: %s", NAME_TEMPLATE, name);
Expand Down

0 comments on commit ecf5826

Please sign in to comment.