Bug 43717 - gnu/java/nio/channels/FileChannelImpl (smallTransferTo) doesn't conform to the spec
Summary: gnu/java/nio/channels/FileChannelImpl (smallTransferTo) doesn't conform to th...
Alias: None
Product: classpath
Classification: Unclassified
Component: classpath (show other bugs)
Version: 0.98
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2010-04-10 21:32 UTC by Debian GCC Maintainers
Modified: 2010-04-10 21:32 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Debian GCC Maintainers 2010-04-10 21:32:53 UTC
[forwarded from http://bugs.debian.org/571532]

running ant 1.8 on gij (4.4/4.5) terminates with a BUS error (on hppa-linux); that the only debian port still using gij as default VM, but should be present on other archs as well.

bug reporter writes:

The problem is triggered by this line, for any small file,
which seems to me allowed by java specification

srcChannel.transferTo(0, FileUtils.BUF_SIZE,destChannel);


  An attempt is made to read up to count bytes from the source channel and
  write them to this channel's file starting at the given position. An
  invocation of this method may or may not transfer all of the requested
  bytes; whether or not it does so depends upon the natures and states of
  the channels. Fewer than the requested number of bytes will be
  if the source channel has fewer than count bytes remaining, or if the
  source channel is non-blocking and has fewer than count bytes
  immediately available in its input buffer.

It is implemented in 
via smallTransferTo() via map() via mapImpl().

The specification of map() explicitely states:

  Many of the details of memory-mapped files are inherently dependent upon
  the underlying operating system and are therefore unspecified. The
  behavior of this method when the requested region is not completely
  contained within this channel's file is unspecified.

The transferTo(0, 8192, ...) is translated into mmap() of 8192 
bytes from file of size 1701 on architecture with pagesize 4096.
This system call succeeds, the later acces to 2nd page fails.
Moreover, it looks like transferTo(0, 4096, ...) would write
4096 bytes to destination file from file with size 1701.

The implementaion of smallTransferTo() should be fixed.

It can be shown by this snippet:

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

public class Tra {

  public static void main(String[] args) throws Exception {
    if (args.length != 2) {
      System.out.println("arguments: sourcefile destfile");
    FileChannel in = new FileInputStream(args[0]).getChannel(),
               out = new FileOutputStream(args[1]).getChannel();

    in.transferTo(0, 4096, out);