On Mon, 23 Jun 2025 21:18:09 GMT, Alex Menkov <[email protected]> wrote:
>> Coleen Phillimore has updated the pull request incrementally with one
>> additional commit since the last revision:
>>
>> Add a byte buffer version and rename parameters.
>
> test/lib/RedefineClassHelper.java line 87:
>
>> 85: }
>> 86: return 0;
>> 87: }
>
> I understand, that this is copy of the old code, but this method does not
> look good.
> - it would be better to return -1 if the string not found (0 is valid offset)
> - calculation of the buf's upper bound is incorrect when offset > 0
> I'd suggest to update it to something like (not tested, also need to update
> callers to compare with -1)
>
>
> private static int getStringIndex(String needle, byte[] buf, int offset) {
> byte[] needleArray = needle.getBytes(StandardCharsets.US_ASCII);
> for (int i = offset; i < buf.length - needleArray.length; i++)
> if (Arrays.equals(buf, offset, offset + needleArray.length,
> needleArray, 0, needleArray.length)) {
> return offset;
> }
> }
> return -1;
> }
I did copy this code. I was hoping instead of class byte modifications that
someone would suggest a Classfile API way to modify the class file bytes.
@liach ? That way the class names don't have to be the same length. Above
seems better code but I have to debug it now.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25857#discussion_r2163791674