bug-classpath
[Top][All Lists]
Advanced

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

[Bug classpath/32030] New: RandomAccessFile truncates on rw access


From: Steve dot Blackburn at anu dot edu dot au
Subject: [Bug classpath/32030] New: RandomAccessFile truncates on rw access
Date: 22 May 2007 04:28:52 -0000

There appears to be a very simple error in gnu_java_nio_VMChannel.c, which
truncates files opened in "rw" mode.  See patch below.

This bug showed up for us on the transition from 0.92 to 0.93 when
FileChannelImpl was refactored with the side effect that the open is now
performed by the native open(path, mode) in VMChannel where it had been
previously been performed by the native open(path, mode) in FileChannelImpl.  

These two different native implementations of open() are very different, and
the one in VMChannel is wrong, I think.  Presumably whoever did the refactor
did not realize it would result in a different native implementation open being
called (and that the new one might have a bug in it).

The bug is easily repeatable (see below) and I think the fix is trivial.

Cheers,

--Steve

Index: native/jni/java-nio/gnu_java_nio_VMChannel.c
===================================================================
RCS file:
/sources/classpath/classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c,v
retrieving revision 1.17
diff -r1.17 gnu_java_nio_VMChannel.c
1630c1630
<               ((nmode == O_RDWR || nmode == O_WRONLY) ? O_TRUNC : 0))
---
>               ((nmode == O_WRONLY) ? O_TRUNC : 0))

Trivial test case (should print "true", prints "false" for cvs head and
versions > 0.92).

import java.io.*;

/**
 * [ 1722506 ] dacapo eclipse fails EOF exceptions 
 *
http://sourceforge.net/tracker/index.php?func=detail&aid=1722506&group_id=128805&atid=712768
 */
public class R1722506 {
  public static void main(String[] args) {
    String filename = System.getProperty("java.io.tmpdir")+"/filetest.tmp";
    try {    
      File newIndexFile = new File(filename);
      DataOutputStream stream = new DataOutputStream(new
BufferedOutputStream(new FileOutputStream(newIndexFile, false), 2048));
      for (int i = 0; i < 50; i++)
        stream.writeInt(i);
      stream.close();
      long streamLen = (new File(filename)).length();
      RandomAccessFile raFile = new RandomAccessFile(filename, "rw");
      System.out.println(streamLen == (new File(filename)).length());
      raFile.close();
    } catch (Exception e) {
      System.err.println("Caught exception: "+e);
    } finally {
      (new File(filename)).delete();
    }
  }
}


-- 
           Summary: RandomAccessFile truncates on rw access
           Product: classpath
           Version: unspecified
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: classpath
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Steve dot Blackburn at anu dot edu dot au


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32030





reply via email to

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