[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/43717] New: gnu/java/nio/channels/FileChannelImpl (smallT

From: debian-gcc at lists dot debian dot org
Subject: [Bug classpath/43717] New: gnu/java/nio/channels/FileChannelImpl (smallTransferTo) doesn't conform to the spec
Date: 10 Apr 2010 21:32:54 -0000

[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);

           Summary: gnu/java/nio/channels/FileChannelImpl (smallTransferTo)
                    doesn't conform to the spec
           Product: classpath
           Version: 0.98
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: classpath
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: debian-gcc at lists dot debian dot org


reply via email to

[Prev in Thread] Current Thread [Next in Thread]