question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Counterintuitive behavior of method io.netty.buffer.AbstractByteBuf#readBytes(int)

See original GitHub issue

Expected behavior

The following code should print both true or both false:

public static void main(String[] args) {
        ByteBuf heapBuffer =  new PooledByteBufAllocator(false).heapBuffer(1, 1).writeByte(1);

        ByteBuf buffer_a = heapBuffer.readBytes(0);
        ByteBuf buffer_b = heapBuffer.readBytes(1);

        System.out.println(buffer_a.isDirect());
        System.out.println(buffer_b.isDirect());
    }

Actual behavior

buffer_a.isDirect() printed true , buffer_b.isDirect() printed false.

Steps to reproduce

See above

Minimal yet complete reproducer code (or URL to code)

See above

Netty version

4.1

JVM version (e.g. java -version)

1.8

OS version (e.g. uname -a)

MacOS

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
laosijikaichelecommented, Jun 5, 2021

@trustin, Thanks a lot for the explanation, it really makes sense someway. Maybe I can add this explanation to the doc of method io.netty.buffer.EmptyByteBuf#isDirect, so that more people can better understand it.

0reactions
trustincommented, Jun 5, 2021

Great. Looking forward to your pull request 🙇

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spark 2.3 java.lang.NoSuchMethodError: io.netty.buffer ...
This is because Hadoop binaries compiled with an older version and need us to just replace them. I haven't faced any issues with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found