We're updating the issue view to help you get more done. 

VMChannel.write will return wrong number of bytes written when writing one byte from a ByteBuffer

Description

VMChannel.write(ByteBuffer src, int pos, int len) will return a wrong number of bytes written when (len=1).

When (len=1), the method calls Filesystem.writeByte(...) and considers the returned value as a number of bytes written. Problem is Filesystem.writeByte() returns an "OK" status (0 <=> one byte written, otherwise an error occurred). Thus the current implementation reports 0 byte written when the writeByte operation succeed.

The bug is located at libraryInterface/GNUClasspath/LGLP/src/gnu/java/nio/VMChannel.java:411

A possible fix:
change the following line

bytes = FileSystem.writeByte(nfd.getNativeFD(),src.get(pos));

by the following line

bytes = ( FileSystem.writeByte(nfd.getNativeFD(),src.get(pos)) == 0 ? 1 : 0 )

This solution however doesn't take care of a possible error status returned.

Environment

Any environment.

Status

Assignee

DaveG

Reporter

quentin sabah

Labels

None

External issue ID

None

Fix versions

Affects versions

3.1.1
3.0.1

Priority

Low