From 3ad113937818f3382e62e33253153fe15aca9d07 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Fri, 2 Aug 2013 20:08:30 +0000 Subject: [PATCH] HBASE-9031 ImmutableBytesWritable.toString() should downcast the bytes before converting to hex string git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1509842 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/io/ImmutableBytesWritable.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/ImmutableBytesWritable.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/ImmutableBytesWritable.java index 0e0cb0a8053..7a13392cd39 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/ImmutableBytesWritable.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/ImmutableBytesWritable.java @@ -212,20 +212,18 @@ implements WritableComparable { */ @Override public String toString() { - StringBuilder sb = new StringBuilder(3*this.bytes.length); - for (int idx = offset; idx < offset + length; idx++) { - // if not the first, put a blank separator in - if (idx != offset) { - sb.append(' '); - } - String num = Integer.toHexString(bytes[idx]); + StringBuilder sb = new StringBuilder(3*this.length); + final int endIdx = this.offset + this.length; + for (int idx = this.offset; idx < endIdx ; idx++) { + sb.append(' '); + String num = Integer.toHexString(0xff & this.bytes[idx]); // if it is only one digit, add a leading 0. if (num.length() < 2) { sb.append('0'); } sb.append(num); } - return sb.toString(); + return sb.length() > 0 ? sb.substring(1) : ""; } /** A Comparator optimized for ImmutableBytesWritable.