Repository: netty/netty
File: buffer/src/main/java/io/netty/buffer/ReadOnlyByteBufferBuf.java (Java)

Code before:

        @Override
        public ByteBuf slice(int index, int length) {
            return new ReadOnlySlicedByteBuf(this, index, length);
        }

        @Override
        public ByteBuf duplicate() {
            return new ReadOnlyDuplicatedByteBuf(this);
        }

        @Override
        public boolean isWritable() {
            return false;
        }

        @Override
        public boolean isWritable(int numBytes) {
            return false;
        }
    }

    @SuppressWarnings("deprecation")
    private static final class ReadOnlyDuplicatedByteBuf extends DuplicatedByteBuf {
        ReadOnlyDuplicatedByteBuf(ByteBuf buffer) {
            super(buffer);
        }

        @Override
        public ByteBuf asReadOnly() {
            return this;
        }

        @Override
        public ByteBuf slice(int index, int length) {
            return new ReadOnlySlicedByteBuf(this, index, length);
        }

        @Override
        public ByteBuf duplicate() {
            return new ReadOnlyDuplicatedByteBuf(this);
        }

        @Override
        public boolean isWritable() {
            return false;
        }

        @Override
        public boolean isWritable(int numBytes) {
            return false;

Review comment (suggestion):
In addition to the above methods, nioBuffer and nioBuffers methods should return read-only ByteBuffer instances. While looking into this I noticed that the override for nioBuffer exists in ReadOnlyByteBufferBuf, but the nioBuffers override is missing.

Something like this for making nioBuffer and nioBuffers return read-only ByteBuffers?
```java
    @Override
    public ByteBuffer nioBuffer(int index, int length) {
        return unwrap().nioBuffer(index, length).asReadOnlyBuffer();
    }

    @Override
    public ByteBuffer[] nioBuffers(int index, int length) {
        ByteBuffer[] byteBuffers = unwrap().nioBuffers(index, length);
        for (int i = 0; i < byteBuffers.length; i++) {
            byteBuffers[i] = byteBuffers[i].asReadOnlyBuffer();
        }
        return byteBuffers;
    }
```

Code after:

        @Override
        public ByteBuf slice(int index, int length) {
            return new ReadOnlySlicedByteBuf(this, index, length);
        }

        @Override
        public ByteBuf duplicate() {
            return new ReadOnlyDuplicatedByteBuf(this);
        }

        @Override
        public boolean isWritable() {
            return false;
        }

        @Override
        public boolean isWritable(int numBytes) {
            return false;
        }

        @Override
        public int ensureWritable(int minWritableBytes, boolean force) {
            return 1;
        }
    }

    @SuppressWarnings("deprecation")
    private static final class ReadOnlyDuplicatedByteBuf extends DuplicatedByteBuf {
        ReadOnlyDuplicatedByteBuf(ByteBuf buffer) {
            super(buffer);
        }

        @Override
        public ByteBuf asReadOnly() {
            return this;
        }

        @Override
        public ByteBuf slice(int index, int length) {
            return new ReadOnlySlicedByteBuf(this, index, length);
        }

        @Override
        public ByteBuf duplicate() {
            return new ReadOnlyDuplicatedByteBuf(this);
        }

        @Override
        public boolean isWritable() {
            return false;