Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BufferUnderflowException in Getting Started #122

Closed
pjulien opened this issue Dec 29, 2014 · 2 comments
Closed

BufferUnderflowException in Getting Started #122

pjulien opened this issue Dec 29, 2014 · 2 comments
Assignees

Comments

@pjulien
Copy link

pjulien commented Dec 29, 2014

I am trying to determine if the following wiki page is out of date or is exposing a bug in the system:

https://github.com/OpenHFT/Chronicle-Queue/blob/master/docs/HowItWorks.md#getting-started

Using Windows 8.1, Java 8u25 and Chronicle Queue 3.3.3 with no modifications other than adding a package declaration, I get the following:

Exception in thread "main" java.lang.IllegalStateException: java.nio.BufferUnderflowException
    at net.openhft.lang.io.AbstractBytes.readObject(AbstractBytes.java:1990)
    at com.test.ExampleCacheMain.main(ExampleCacheMain.java:26)
Caused by: java.nio.BufferUnderflowException
    at net.openhft.lang.io.AbstractBytes.returnOrThrowEndOfBuffer(AbstractBytes.java:195)
    at net.openhft.lang.io.AbstractBytes.readByteOrThrow(AbstractBytes.java:439)
    at net.openhft.lang.io.AbstractBytes.readUnsignedByteOrThrow(AbstractBytes.java:433)
    at net.openhft.lang.io.serialization.BytesMarshallableSerializer.readSerializable(BytesMarshallableSerializer.java:123)
    at net.openhft.lang.io.AbstractBytes.readObject(AbstractBytes.java:1988)
    ... 1 more

Modifying to use readUTF and writeUTF, I get:

Exception in thread "main" java.nio.BufferUnderflowException
    at net.openhft.lang.io.AbstractBytes.returnOrThrowEndOfBuffer(AbstractBytes.java:195)
    at net.openhft.lang.io.AbstractBytes.readByteOrThrow(AbstractBytes.java:439)
    at net.openhft.lang.io.AbstractBytes.readUnsignedByteOrThrow(AbstractBytes.java:433)
    at net.openhft.lang.io.AbstractBytes.readUTF0(AbstractBytes.java:202)
    at net.openhft.lang.io.AbstractBytes.readUTF(AbstractBytes.java:698)
    at com.test.ExampleCacheMain.main(ExampleCacheMain.java:26)
@lburgazzoli lburgazzoli self-assigned this Dec 29, 2014
@lburgazzoli
Copy link
Contributor

There is an error in the GettingStarted: you should always check if there is an Excerpt to read before reading it so you should do:

while(!reader.nextIndex());
Object obj = reader.readObject();
reader.finish();

If you want to read all the Excerpts :

while(true) {
    if(reader.nextIndex()) {
        Object obj = reader.readObject();
        reader.finish();
   } else {
       // sleep, do nothing, yeld, etc
   }
}

I've updated the getting-started guide

@pjulien
Copy link
Author

pjulien commented Dec 29, 2014

Thanks works for me now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants