Aditya Kishore created HBASE-6991: ------------------------------------- Summary: Bytes.toStringBinary() and its counterpart Bytes.toBytesBinary() are not always consistant Key: HBASE-6991 URL: https://issues.apache.org/jira/browse/HBASE-6991 Project: HBase Issue Type: Bug Components: util Affects Versions: 0.96.0 Reporter: Aditya Kishore Assignee: Aditya Kishore
Since "\" is used to escape non-printable character but not treated as special character in conversion, it could lead to unexpected conversion. For example, please consider the following code snippet. {code} public void testConversion() { byte[] original = { '\\', 'x', 'A', 'D' }; String stringFromBytes = Bytes.toStringBinary(original); byte[] converted = Bytes.toBytesBinary(stringFromBytes); System.out.println("Original: " + Arrays.toString(original)); System.out.println("Converted: " + Arrays.toString(converted)); System.out.println("Reversible?: " + (Bytes.compareTo(original, converted) == 0)); } Output: ------- Original: [92, 120, 65, 68] Converted: [-83] Reversible?: false {code} The "\" character needs to be treated as special and must be encoded as a non-printable character ("\x5C") to avoid any kind of unambiguity during conversion. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira