Skip to content

Commit

Permalink
fix: check for not null input for Id classes
Browse files Browse the repository at this point in the history
Fixes #145
  • Loading branch information
olavloite committed Apr 20, 2020
1 parent 66b10ac commit 64de699
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 64de699

Please sign in to comment.