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

Implementation of MantaSeekableByteChannel.read(ByteBuffer) is broken #468

Open
dekobon opened this issue Jan 17, 2019 · 2 comments
Open
Assignees

Comments

@dekobon
Copy link
Contributor

dekobon commented Jan 17, 2019

Looking at our implementation of MantaSeekableByteChannel.read(ByteBuffer) it appears that we don't follow the API contract:

    public int read(final ByteBuffer dst) throws IOException {
        if (!open) {
            throw new ClosedChannelException();
        }

        final MantaObjectInputStream stream = connectOrGetResponse();
        final long size = size();

        if (position.get() >= size) {
            return EOF;
        }

        final byte[] buff = dst.array();
        final int bytesRead = stream.read(buff);

        position.addAndGet(bytesRead);

        return bytesRead;
    }

Interface documentation:

    /**
     * Reads a sequence of bytes from this channel into the given buffer.
     *
     * <p> Bytes are read starting at this channel's current position, and
     * then the position is updated with the number of bytes actually read.
     * Otherwise this method behaves exactly as specified in the {@link
     * ReadableByteChannel} interface.
     */

This method is not reading data into the supplied byte buffer at all. In the Java source code, many of the implementations that implement this method use the static method IOUtil.read. Within that implementation you can see that data is clearly being read into the ByteBuffer. Whereas in the MantaSeekableByteChannel implementation no data is being read into the ByteBuffer.

@indianwhocodes
Copy link
Contributor

A good reference here would be bugpatterns/ByteBufferBackingArray.

@indianwhocodes
Copy link
Contributor

Currently active branch: ashwin-fix-468 is tracking this issue.

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

No branches or pull requests

2 participants