Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Bug in sun.nio.ch.IOUtil (regression in R28.1?)

855725Apr 15 2011 — edited May 12 2011
I believe that I have discovered a bug in sun.nio.ch.IOUtil.write(java.io.FileDescriptor, java.nio.ByteBuffer, long, sun.nio.ch.NativeDispatcher, java.lang.Object). The bug triggers the following stack trace in the test case:
Exception in thread "Main Thread" java.nio.ReadOnlyBufferException
    at java.nio.ByteBuffer.array(ByteBuffer.java:723)
    at sun.nio.ch.IOUtil.write(IOUtil.java:168)
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
    at NioBug.main(NioBug.java:15)
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
 
public class NioBug {
    public static void main(String[] args) throws IOException {
	SocketChannel sc = SocketChannel.open(new InetSocketAddress("www.google.com", 80));
	sc.configureBlocking(false);
 
	ByteBuffer write = ByteBuffer.wrap("GET /\n".getBytes()).asReadOnlyBuffer();
 
	while (write.hasRemaining()) {
	    sc.write(write);
	}
    }
}
The test attempts to write the contents of a read-only heap ByteBuffer to a SocketChannel. Inside sun.nio.ch.IOUtil.write(...) in order to copy the heap data in to a temporary direct ByteBuffer an unguarded call is made to ByteBuffer.array() which triggers the ReadOnlyBufferException seen in the test as the supplied buffer is not allowed to expose its contents to potential mutators.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 9 2011
Added on Apr 15 2011
1 comment
595 views