fix bug: string out of bounds when construct illegal tablename error message (#2884)
Signed-off-by: Viraj Jasani <vjasani@apache.org> Signed-off-by: stack <stack@apache.org>
This commit is contained in:
parent
ca672aceee
commit
098f7c0bd4
|
@ -192,16 +192,14 @@ public final class TableName implements Comparable<TableName> {
|
||||||
if(end - start < 1) {
|
if(end - start < 1) {
|
||||||
throw new IllegalArgumentException(isSnapshot ? "Snapshot" : "Table" + " qualifier must not be empty");
|
throw new IllegalArgumentException(isSnapshot ? "Snapshot" : "Table" + " qualifier must not be empty");
|
||||||
}
|
}
|
||||||
|
String qualifierString = Bytes.toString(qualifierName, start, end - start);
|
||||||
if (qualifierName[start] == '.' || qualifierName[start] == '-') {
|
if (qualifierName[start] == '.' || qualifierName[start] == '-') {
|
||||||
throw new IllegalArgumentException("Illegal first character <" + qualifierName[start] +
|
throw new IllegalArgumentException("Illegal first character <" + qualifierName[start] +
|
||||||
"> at 0. " + (isSnapshot ? "Snapshot" : "User-space table") +
|
"> at 0. " + (isSnapshot ? "Snapshot" : "User-space table") +
|
||||||
" qualifiers can only start with 'alphanumeric " +
|
" qualifiers can only start with 'alphanumeric " +
|
||||||
"characters' from any language: " +
|
"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)) {
|
if (qualifierString.equals(DISALLOWED_TABLE_NAME)) {
|
||||||
// Per https://zookeeper.apache.org/doc/r3.4.10/zookeeperProgrammers.html#ch_zkDataModel
|
// Per https://zookeeper.apache.org/doc/r3.4.10/zookeeperProgrammers.html#ch_zkDataModel
|
||||||
// A znode named "zookeeper" is disallowed by zookeeper.
|
// A znode named "zookeeper" is disallowed by zookeeper.
|
||||||
|
|
|
@ -137,7 +137,7 @@ public class TestTableName {
|
||||||
|
|
||||||
@Test public void testIllegalHTableNames() {
|
@Test public void testIllegalHTableNames() {
|
||||||
for (String tn : illegalTableNames) {
|
for (String tn : illegalTableNames) {
|
||||||
assertThrows(Exception.class,
|
assertThrows(IllegalArgumentException.class,
|
||||||
() -> TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn)));
|
() -> TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue