RFR 8251989: Hex encoder and decoder utility
Raffaello Giulietti
raffaello.giulietti at gmail.com
Fri Aug 21 15:44:14 UTC 2020
Hi Roger,
I'm only a contributor, not an official reviewer. Despite this, I would
like to make some notes about the encoder part.
(1) Comparing with other APIs that accept a range of a byte[], my
understanding is that encode(byte[], int, int) should throw IOOE when
index < 0 or too big, even if length == 0. Since other parts of the code
already invokes Objects.checkFromIndexSize() in other methods, it would
be more consistent to add this check to this one as well.
(2) The code on L.334 throws an exception when encodeOptDelim() is
invoked with an empty byte[]. This can happen precisely because the
checks mentioned in (1) are not strict enough. E.g., given an
appropriate encoder, encode(new byte[0], 0, 1) will invoke
encodeOptDelim() and throw on L.334
(3) I guess "NYI" on L.343 stands for "not yet implemented", but
shouldn't this more likely be an AssertionError? What else needs to be
implemented here?
(4) The private toHex(int, boolean) can be declared static.
(5) To maintain consistency with the other ranges, on L.599 "0123456789"
could be replaced by "0-9".
(6) As already noted by Tagir, there's a duplication of checks in L.290-291
Greetings
Raffaello
> Please review a java.util.Hex API to encode and decode hexadecimal
> strings to and from byte arrays.
>
> Within the JDK and JDK tests there are multiple implementations to
> encode and decode
> hexadecimal strings to byte arrays. Hex encoders and decoders support
> upper or lower case hexadecimal characters, delimiters, prefix, and suffix.
> The API is modeled after the java.util.Base64 API providing static
> factories,
> immutable threadsafe instances with methods to encode to and decode from
> string and StringBuilder.
More information about the core-libs-dev
mailing list