diff --git a/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java b/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java index 076760bbc72..5862f15db29 100644 --- a/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java +++ b/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java @@ -40,6 +40,8 @@ import org.apache.hadoop.hbase.util.Bytes; 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 implements WritableComparable * @throws IllegalArgumentException If not null and not a legitimate family * name: i.e. 'printable' and ends in a ':' (Null passes are allowed because * b 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)); diff --git a/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java b/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java new file mode 100644 index 00000000000..390aec873d9 --- /dev/null +++ b/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java @@ -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()); + } + } +}