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.

Activity

Show:
dafeng
July 23, 2011, 12:50 AM

That is a common bug, even with Harmony lib.

dafeng
July 23, 2011, 12:52 AM

some problem paste patch. Actually change "return 0" to "return rc"

quentin sabah
August 4, 2011, 9:00 AM

Fix VMChannel.write(ByteBuffer,int,int) to report right number of bytes written when writing one byte and throw an IOException if FileSystem.writeByte failed.

DaveG
December 21, 2011, 7:41 PM

Applied VMChannel.java.patch in 10409:0766fceb8b61.

Looked, but did not see similar problem in Harmony libraryInterface code.

Decided to not change meaning of sysWriteByte return code since it is called from more than just this one place.

DaveG
February 9, 2013, 10:49 PM

bulk close of all resolved issues in preparation for 3.1.3 release.

Assignee

DaveG

Reporter

quentin sabah

Labels

None

Fix versions

Affects versions

Priority

Low
Configure