hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mberto...@apache.org
Subject [4/4] hbase git commit: HBASE-13050 Empty Namespace validation
Date Wed, 18 Feb 2015 07:40:58 GMT
HBASE-13050 Empty Namespace validation

Signed-off-by: Matteo Bertozzi <matteo.bertozzi@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/7b045d14
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/7b045d14
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/7b045d14

Branch: refs/heads/master
Commit: 7b045d143ab91089c1c13f3095389fb5de4111f5
Parents: f64d63d
Author: Abhishek Kumar <abhishek.kr@huawei.com>
Authored: Tue Feb 17 18:09:27 2015 +0530
Committer: Matteo Bertozzi <matteo.bertozzi@cloudera.com>
Committed: Wed Feb 18 08:33:19 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/hadoop/hbase/TableName.java     | 16 ++++++++--------
 .../org/apache/hadoop/hbase/util/TestTableName.java | 15 +++++++++++----
 2 files changed, 19 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/7b045d14/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
index 5167157..245bef5 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
@@ -208,21 +208,21 @@ public final class TableName implements Comparable<TableName>
{
   /**
    * Valid namespace characters are [a-zA-Z_0-9]
    */
-  public static void isLegalNamespaceName(byte[] namespaceName, int offset, int length) {
-    for (int i = offset; i < length; i++) {
+  public static void isLegalNamespaceName(final byte[] namespaceName,
+                                           final int start,
+                                           final int end) {
+    if(end - start < 1) {
+      throw new IllegalArgumentException("Namespace name must not be empty");
+    }
+    for (int i = start; i < end; i++) {
       if (Character.isLetterOrDigit(namespaceName[i])|| namespaceName[i] == '_') {
         continue;
       }
       throw new IllegalArgumentException("Illegal character <" + namespaceName[i] +
         "> at " + i + ". Namespaces can only contain " +
         "'alphanumeric characters': i.e. [a-zA-Z_0-9]: " + Bytes.toString(namespaceName,
-          offset, length));
+          start, end));
     }
-    if(offset == length)
-      throw new IllegalArgumentException("Illegal character <" + namespaceName[offset]
+
-          "> at " + offset + ". Namespaces can only contain " +
-          "'alphanumeric characters': i.e. [a-zA-Z_0-9]: " + Bytes.toString(namespaceName,
-            offset, length));
   }
 
   public byte[] getName() {

http://git-wip-us.apache.org/repos/asf/hbase/blob/7b045d14/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestTableName.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestTableName.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestTableName.java
index 94070f3..f585f47 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestTableName.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestTableName.java
@@ -23,7 +23,6 @@ import java.util.Map;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.fail;
 
@@ -53,8 +52,8 @@ public class TestTableName extends TestWatcher {
   public TableName getTableName() {
     return tableName;
   }
-  
-  String emptyTableNames[] ={"", " "};
+
+  String emptyNames[] ={"", " "};
   String invalidNamespace[] = {":a", "%:a"};
   String legalTableNames[] = { "foo", "with-dash_under.dot", "_under_start_ok",
       "with-dash.with_underscore", "02-01-2012.my_table_01-02", "xyz._mytable_", "9_9_0.table_02"
@@ -74,8 +73,16 @@ public class TestTableName extends TestWatcher {
   }
 
   @Test(expected = IllegalArgumentException.class)
+  public void testEmptyNamespaceName() {
+    for (String nn : emptyNames) {
+      TableName.isLegalNamespaceName(Bytes.toBytes(nn));
+      fail("invalid Namespace name " + nn + " should have failed with IllegalArgumentException");
+    }
+  }
+
+  @Test(expected = IllegalArgumentException.class)
   public void testEmptyTableName() {
-    for (String tn : emptyTableNames) {
+    for (String tn : emptyNames) {
       TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
       fail("invalid tablename " + tn + " should have failed with IllegalArgumentException");
     }


Mime
View raw message