You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2012/04/18 22:25:51 UTC

svn commit: r1327666 - in /hbase/trunk/src: main/java/org/apache/hadoop/hbase/HColumnDescriptor.java test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java

Author: stack
Date: Wed Apr 18 20:25:50 2012
New Revision: 1327666

URL: http://svn.apache.org/viewvc?rev=1327666&view=rev
Log:
HBASE-3585 isLegalFamilyName() can throw ArrayOutOfBoundException

Added:
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java
Modified:
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java?rev=1327666&r1=1327665&r2=1327666&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java Wed Apr 18 20:25:50 2012
@@ -40,6 +40,8 @@ import org.apache.hadoop.hbase.util.Byte
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.WritableComparable;
 
+import com.google.common.base.Preconditions;
+
 /**
  * An HColumnDescriptor contains information about a column family such as the
  * number of versions, compression settings, etc.
@@ -379,12 +381,13 @@ public class HColumnDescriptor implement
    * @throws IllegalArgumentException If not null and not a legitimate family
    * name: i.e. 'printable' and ends in a ':' (Null passes are allowed because
    * <code>b</code> can be null when deserializing).  Cannot start with a '.'
-   * either.
+   * either. Also Family can not be an empty value.
    */
   public static byte [] isLegalFamilyName(final byte [] b) {
     if (b == null) {
       return b;
     }
+    Preconditions.checkArgument(b.length != 0, "Family name can not be empty");
     if (b[0] == '.') {
       throw new IllegalArgumentException("Family names cannot start with a " +
         "period: " + Bytes.toString(b));

Added: hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java?rev=1327666&view=auto
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java (added)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java Wed Apr 18 20:25:50 2012
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/** Tests the HColumnDescriptor with appropriate arguments */
+public class TestHColumnDescriptor {
+
+  @Test
+  @SuppressWarnings("deprecation")
+  /** Tests HColumnDescriptor with empty familyName*/
+  public void testHColumnDescriptorShouldThrowIAEWhenFamiliyNameEmpty()
+      throws Exception {
+    try {
+      new HColumnDescriptor("".getBytes());
+    } catch (IllegalArgumentException e) {
+      assertEquals("Family name can not be empty", e.getLocalizedMessage());
+    }
+  }
+}