zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brandon Berg (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (ZOOKEEPER-2763) Utils.toCsvBuffer() omits leading 0 for bytes < 0x10
Date Wed, 19 Apr 2017 06:38:41 GMT

     [ https://issues.apache.org/jira/browse/ZOOKEEPER-2763?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Brandon Berg updated ZOOKEEPER-2763:
------------------------------------
    Description: 
org.apache.jute.Utils.toCsvBuffer(), which converts a byte array to a string containing the
hex representation of that byte array, omits the leading zero for any byte less than 0x10,
due to its use of Integer.toHexString, which has the same behavior.

https://github.com/apache/zookeeper/blob/master/src/java/main/org/apache/jute/Utils.java#L234

One consequence of this is that the hex strings printed by ClientCnxn.Packet.toString(), used
in the debug logging for ClientCnxn.readResponse(), cannot be parsed to determine the result
of a Zookeeper request from client debug logs.

Utils.toXmlBuffer() appears to have the same issue.

A simple proposed fix is to replace the for loop with the following:

{code}
        for(int idx = 0; idx < barr.length; idx++) {
            byte b = barr[idx];
            if (b >= 0 && b <= 0xf) {
                sb.append('0');
            }
            sb.append(Integer.toHexString(b));
        }
{code}

  was:
org.apache.jute.Utils.toCsvBuffer(), which converts a byte array to a string containing the
hex representation of that byte array, omits the leading zero for any byte less than 0x10,
due to its use of Integer.toHexString, which has the same behavior.

https://github.com/apache/zookeeper/blob/master/src/java/main/org/apache/jute/Utils.java#L234

One consequence of this is that the hex strings printed by ClientCnxn.Packet.toString(), used
in the debug logging for ClientCnxn.readResponse(), cannot be parsed to determine the result
of a Zookeeper request from client debug logs.

Utils.toXmlBuffer() appears to have the same issue.

A simple proposed fix is to replace the for loop with the following:

{code}
        for(int idx = 0; idx < barr.length; idx++) {
            byte b = barr[idx];
            if (b >= 0 && b <= 0xf) {
                sb.append('0');
            }
            sb.append(Integer.toHexString(barr[idx]));
        }
{code}


> Utils.toCsvBuffer() omits leading 0 for bytes < 0x10
> ----------------------------------------------------
>
>                 Key: ZOOKEEPER-2763
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2763
>             Project: ZooKeeper
>          Issue Type: Bug
>          Components: jute
>    Affects Versions: 3.5.2
>            Reporter: Brandon Berg
>            Priority: Minor
>
> org.apache.jute.Utils.toCsvBuffer(), which converts a byte array to a string containing
the hex representation of that byte array, omits the leading zero for any byte less than 0x10,
due to its use of Integer.toHexString, which has the same behavior.
> https://github.com/apache/zookeeper/blob/master/src/java/main/org/apache/jute/Utils.java#L234
> One consequence of this is that the hex strings printed by ClientCnxn.Packet.toString(),
used in the debug logging for ClientCnxn.readResponse(), cannot be parsed to determine the
result of a Zookeeper request from client debug logs.
> Utils.toXmlBuffer() appears to have the same issue.
> A simple proposed fix is to replace the for loop with the following:
> {code}
>         for(int idx = 0; idx < barr.length; idx++) {
>             byte b = barr[idx];
>             if (b >= 0 && b <= 0xf) {
>                 sb.append('0');
>             }
>             sb.append(Integer.toHexString(b));
>         }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message