RFR 8251989: Hex encoder and decoder utility

Roger Riggs Roger.Riggs at oracle.com
Fri Aug 21 16:38:09 UTC 2020


Hi Rafaello,

On 8/21/20 11:44 AM, Raffaello Giulietti wrote:
> Hi Roger,
>
> I'm only a contributor, not an official reviewer. Despite this, I 
> would like to make some notes about the encoder part.
Reviews are always appreciated, whether Reviewer or not.
>
>
> (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.
yes, will add that, both the encode methods should have the same range 
checks.
>
> (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
Right, adding the check to 1 will keep it from getting that far.
>
> (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?
Good point, I'll refactor it to avoid duplicate checks before calling 
the private function and in the function.
>
> (4) The private toHex(int, boolean) can be declared static.
ok
>
> (5) To maintain consistency with the other ranges, on L.599 
> "0123456789" could be replaced by "0-9".
ok
>
> (6) As already noted by Tagir, there's a duplication of checks in 
> L.290-291
fixed.

I'll let some of the higher level API questions settle before updating 
the webrev.

Thanks, Roger

>
>
> 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