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 b659d141f93..62668ec7a4d 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 @@ -192,16 +192,14 @@ public final class TableName implements Comparable { if(end - start < 1) { throw new IllegalArgumentException(isSnapshot ? "Snapshot" : "Table" + " qualifier must not be empty"); } + String qualifierString = Bytes.toString(qualifierName, start, end - start); if (qualifierName[start] == '.' || qualifierName[start] == '-') { throw new IllegalArgumentException("Illegal first character <" + qualifierName[start] + "> at 0. " + (isSnapshot ? "Snapshot" : "User-space table") + " qualifiers can only start with 'alphanumeric " + "characters' from any language: " + - Bytes.toString(qualifierName, start, end)); + qualifierString); } - // Treat the bytes as UTF-8 - String qualifierString = new String( - qualifierName, start, (end - start), StandardCharsets.UTF_8); if (qualifierString.equals(DISALLOWED_TABLE_NAME)) { // Per https://zookeeper.apache.org/doc/r3.4.10/zookeeperProgrammers.html#ch_zkDataModel // A znode named "zookeeper" is disallowed by zookeeper. diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java index e1cd52adafe..a908a483db0 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java @@ -137,7 +137,7 @@ public class TestTableName { @Test public void testIllegalHTableNames() { for (String tn : illegalTableNames) { - assertThrows(Exception.class, + assertThrows(IllegalArgumentException.class, () -> TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn))); } }