Skip to content

the result of ByteBufUtil.indexOf(ByteBuf needle, ByteBuf haystack) wrong #11963

Closed
@shichaoyuan

Description

@shichaoyuan

Expected behavior

        ByteBuf haystack = Unpooled.copiedBuffer("+PONG\r\n", CharsetUtil.UTF_8);
        ByteBuf needle = Unpooled.copiedBuffer("\r\n", CharsetUtil.UTF_8);
        haystack.readByte();

        int index = ByteBufUtil.indexOf(needle ,haystack);

        System.out.println(index);

expected result is 5.

Actual behavior

actual result is 4.

Steps to reproduce

Minimal yet complete reproducer code (or URL to code)

Netty version

4.1.73.Final-SNAPSHOT

JVM version (e.g. java -version)

openjdk version "11.0.13" 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.21.10)
OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.21.10, mixed mode, sharing)

OS version (e.g. uname -a)

Linux XPS-13-9310 5.13.0-22-generic #22-Ubuntu SMP Fri Nov 5 13:21:36 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Activity

chrisvest

chrisvest commented on Jan 5, 2022

@chrisvest
Member

Thanks for the report, preparing a fix.

added a commit that references this issue on Jan 5, 2022
9c98259
shichaoyuan

shichaoyuan commented on Jan 5, 2022

@shichaoyuan
Author

good

wanglunhui2012

wanglunhui2012 commented on Jan 5, 2022

@wanglunhui2012
Contributor

this is ByteBuf feature,readByte() make readIndex + 1,so the first index is P rather than +.

added 2 commits that reference this issue on Jan 5, 2022
195b849
fdf1b55
added a commit that references this issue on Jan 20, 2022
47c146d
added a commit that references this issue on Jul 8, 2022
5a74ede
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @chrisvest@shichaoyuan@wanglunhui2012

      Issue actions

        the result of `ByteBufUtil.indexOf(ByteBuf needle, ByteBuf haystack)` wrong · Issue #11963 · netty/netty