Skip to content

Commit 4737330

Browse files
saintstackwchevreuil
authored andcommitted
HBASE-25512 May throw StringIndexOutOfBoundsException when construct illegal tablename error apache#2884
This revert of a revert reapplies the PR; the original application was missing the HBASE JIRA #; thats why it was reverted and then reapplied w/ the JIRA # added. This reverts commit 16fe1e9.
1 parent dc9bda6 commit 4737330

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,14 @@ public static void isLegalTableQualifierName(final byte[] qualifierName,
192192
if(end - start < 1) {
193193
throw new IllegalArgumentException(isSnapshot ? "Snapshot" : "Table" + " qualifier must not be empty");
194194
}
195+
String qualifierString = Bytes.toString(qualifierName, start, end - start);
195196
if (qualifierName[start] == '.' || qualifierName[start] == '-') {
196197
throw new IllegalArgumentException("Illegal first character <" + qualifierName[start] +
197198
"> at 0. " + (isSnapshot ? "Snapshot" : "User-space table") +
198199
" qualifiers can only start with 'alphanumeric " +
199200
"characters' from any language: " +
200-
Bytes.toString(qualifierName, start, end));
201+
qualifierString);
201202
}
202-
// Treat the bytes as UTF-8
203-
String qualifierString = new String(
204-
qualifierName, start, (end - start), StandardCharsets.UTF_8);
205203
if (qualifierString.equals(DISALLOWED_TABLE_NAME)) {
206204
// Per https://zookeeper.apache.org/doc/r3.4.10/zookeeperProgrammers.html#ch_zkDataModel
207205
// A znode named "zookeeper" is disallowed by zookeeper.

hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public int hashCode() {
137137

138138
@Test public void testIllegalHTableNames() {
139139
for (String tn : illegalTableNames) {
140-
assertThrows(Exception.class,
140+
assertThrows(IllegalArgumentException.class,
141141
() -> TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn)));
142142
}
143143
}

0 commit comments

Comments
 (0)