RFR: 8251989: Hex formatting and parsing utility [v6]

Roger Riggs rriggs at openjdk.java.net
Tue Oct 20 14:45:25 UTC 2020


On Tue, 20 Oct 2020 10:26:59 GMT, Chris Hegarty <chegar at openjdk.org> wrote:

>> Roger Riggs has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Correct length of StringBuilder in formatHex;
>>   Correct bug in formatHex(char[], 2, 3) and add test for subranges of char[]
>
> src/java.base/share/classes/java/util/HexFormat.java line 90:
> 
>> 88:  *     assert(byteStr.equals("7f"));
>> 89:  *     assert(b == byteVal);
>> 90:  *
> 
> I understand why this is the case, but the example is highlighting that a roundtrip from byte is not possible :-(

In the string form, the value is unsigned and not known to be a byte.
The example should reinforce that point by being explicit about casting the value back to a byte.
            byte byteVal = (byte)hex.fromHexDigits(byteStr);
            assert(byteStr.equals("7f"));
            assert(b == byteVal);```

-------------

PR: https://git.openjdk.java.net/jdk/pull/482


More information about the core-libs-dev mailing list