This is an automated email from the ASF dual-hosted git repository.
blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/master by this push:
new 629da77 API: Add more null checks to TableIdentifier (#2703)
629da77 is described below
commit 629da77952eb2ec4fbcd00613a8b8b3c1e47ec33
Author: Eduard Tudenhöfner <[email protected]>
AuthorDate: Thu Jun 17 20:31:47 2021 +0200
API: Add more null checks to TableIdentifier (#2703)
---
.../apache/iceberg/catalog/TableIdentifier.java | 5 +++-
.../iceberg/catalog/TestTableIdentifier.java | 27 ++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/api/src/main/java/org/apache/iceberg/catalog/TableIdentifier.java
b/api/src/main/java/org/apache/iceberg/catalog/TableIdentifier.java
index 05de7fd..ecbaa06 100644
--- a/api/src/main/java/org/apache/iceberg/catalog/TableIdentifier.java
+++ b/api/src/main/java/org/apache/iceberg/catalog/TableIdentifier.java
@@ -36,6 +36,7 @@ public class TableIdentifier {
private final String name;
public static TableIdentifier of(String... names) {
+ Preconditions.checkArgument(names != null, "Cannot create table identifier
from null array");
Preconditions.checkArgument(names.length > 0, "Cannot create table
identifier without a table name");
return new TableIdentifier(Namespace.of(Arrays.copyOf(names, names.length
- 1)), names[names.length - 1]);
}
@@ -45,12 +46,14 @@ public class TableIdentifier {
}
public static TableIdentifier parse(String identifier) {
+ Preconditions.checkArgument(identifier != null, "Cannot parse table
identifier: null");
Iterable<String> parts = DOT.split(identifier);
return TableIdentifier.of(Iterables.toArray(parts, String.class));
}
private TableIdentifier(Namespace namespace, String name) {
- Preconditions.checkArgument(name != null && !name.isEmpty(), "Invalid
table name %s", name);
+ Preconditions.checkArgument(name != null && !name.isEmpty(), "Invalid
table name: null or empty");
+ Preconditions.checkArgument(namespace != null, "Invalid Namespace: null");
this.namespace = namespace;
this.name = name;
}
diff --git
a/api/src/test/java/org/apache/iceberg/catalog/TestTableIdentifier.java
b/api/src/test/java/org/apache/iceberg/catalog/TestTableIdentifier.java
index b67bdcd..39f05dd 100644
--- a/api/src/test/java/org/apache/iceberg/catalog/TestTableIdentifier.java
+++ b/api/src/test/java/org/apache/iceberg/catalog/TestTableIdentifier.java
@@ -19,6 +19,7 @@
package org.apache.iceberg.catalog;
+import org.assertj.core.api.Assertions;
import org.junit.Assert;
import org.junit.Test;
@@ -54,4 +55,30 @@ public class TestTableIdentifier {
TableIdentifier.of("Catalog", "dB", "TBL").toLowerCase(),
TableIdentifier.of("catalog", "db", "tbl"));
}
+
+ @Test
+ public void testInvalidTableName() {
+ Assertions.assertThatThrownBy(() -> TableIdentifier.of(Namespace.empty(),
""))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Invalid table name: null or empty");
+
+ Assertions.assertThatThrownBy(() -> TableIdentifier.of(Namespace.empty(),
null))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Invalid table name: null or empty");
+ }
+
+ @Test
+ public void testNulls() {
+ Assertions.assertThatThrownBy(() -> TableIdentifier.of((String[]) null))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Cannot create table identifier from null array");
+
+ Assertions.assertThatThrownBy(() -> TableIdentifier.parse(null))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Cannot parse table identifier: null");
+
+ Assertions.assertThatThrownBy(() -> TableIdentifier.of(null, "name"))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Invalid Namespace: null");
+ }
}