This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libgcj/7528: java.io.RandomAccessFile.skipBytes should return bytes skipped, not position


>Number:         7528
>Category:       libgcj
>Synopsis:       java.io.RandomAccessFile.skipBytes should return bytes skipped, not position
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Aug 07 10:36:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Jesse Rosenstock
>Release:        3.3 20020807 (experimental)
>Organization:
>Environment:
System: Linux churchill 2.4.3-12 #1 Fri Jun 8 15:05:56 EDT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --enable-threads=posix --prefix=/home/user/jmr/app/gcc --enable-shared --enable-languages=c++,java : (reconfigured)  : (reconfigured)  : (reconfigured) 
>Description:
	java.io.RandomAccessFile.skipBytes should return the number of bytes
        skipped.  It currently returns the position in the file.
>How-To-Repeat:
	create RandomAccessFileTest.java:

import java.io.IOException;
import java.io.RandomAccessFile;

public class RandomAccessFileTest {
    public static void main(String[] args) throws IOException {
        RandomAccessFile raf = new RandomAccessFile("foo", "rw");

        raf.writeUTF("foobar");

        raf.seek(0);

        int skipped;
        while ((skipped = raf.skipBytes(1)) == 1)
            System.out.println("skipped 1 byte");

        boolean fail = false;
        if (skipped != 0) {
            fail = true;
            System.out.println("What's going on?  skipped = " + skipped +
                               ", not 0");
        }
        if (raf.getFilePointer() != raf.length()) {
            fail = true;
            System.out.println("What's going on?  filePointer != length!");
            System.out.println("  filePointer = " + raf.getFilePointer());
            System.out.println("  length = " + raf.length());
        }

        System.out.println(fail ? "FAILED" : "PASSED");
    }
}

; gcj -v RandomAccessFileTest.java --main=RandomAccessFileTest -o raft
Reading specs from /home/user/jmr/app/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.3/specs
Reading specs from /home/user/jmr/app/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.3/../../../libgcj.spec
rename spec lib to liborig
Configured with: ../gcc/configure --enable-threads=posix --prefix=/home/user/jmr/app/gcc --enable-shared --enable-languages=c++,java : (reconfigured)  : (reconfigured)  : (reconfigured) 
Thread model: posix
gcc version 3.3 20020807 (experimental)
 /home/user/jmr/app/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.3/jc1 RandomAccessFileTest.java -fhash-synchronization -fno-use-divide-subroutine -fuse-boehm-gc -fnon-call-exceptions -fkeep-inline-functions -quiet -dumpbase RandomAccessFileTest.java -auxbase RandomAccessFileTest -g1 -version -o /tmp/cc7Hot2X.s
GNU Java version 3.3 20020807 (experimental) (i686-pc-linux-gnu)
        compiled by GNU C version 3.3 20020804 (experimental).
Class path starts here:
    ./
    /home/user/jmr/app/gcc/share/java/libgcj-3.3.jar/ (system) (zip)
 as --traditional-format -V -Qy -o /tmp/ccOr5JsQ.o /tmp/cc7Hot2X.s
GNU assembler version 2.12 (i686-pc-linux-gnu) using BFD version 2.12
 /home/user/jmr/app/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.3/jvgenmain RandomAccessFileTestmain /tmp/ccx6MWrK.i
 /home/user/jmr/app/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.3/cc1 /tmp/ccx6MWrK.i -quiet -dumpbase RandomAccessFileTestmain.c -g1 -version -fdollars-in-identifiers -o /tmp/cc7Hot2X.s
GNU C version 3.3 20020807 (experimental) (i686-pc-linux-gnu)
        compiled by GNU C version 3.3 20020804 (experimental).
 as --traditional-format -V -Qy -o /tmp/ccgX694E.o /tmp/cc7Hot2X.s
GNU assembler version 2.12 (i686-pc-linux-gnu) using BFD version 2.12
 /home/user/jmr/app/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.3/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o raft /usr/lib/crt1.o /usr/lib/crti.o /home/user/jmr/app/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.3/crtbegin.o -L/home/user/jmr/app/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.3 -L/home/user/jmr/app/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.3/../../.. /tmp/ccgX694E.o /tmp/ccOr5JsQ.o -lgcc_s -lgcc -lgcj -lm -lpthread -ldl -lgcc_s -lgcc -lc -lgcc_s -lgcc /home/user/jmr/app/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.3/crtend.o /usr/lib/crtn.o

; ./raft
skipped 1 byte
What's going on?  skipped = 2, not 0
What's going on?  filePointer != length!
  filePointer = 2
  length = 8
FAILED

Sun's jdk gives:

; java RandomAccessFileTest
skipped 1 byte
skipped 1 byte
skipped 1 byte
skipped 1 byte
skipped 1 byte
skipped 1 byte
skipped 1 byte
skipped 1 byte
PASSED

>Fix:
cvs diff java/io/RandomAccessFile.java
Index: java/io/RandomAccessFile.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/io/RandomAccessFile.java,v
retrieving revision 1.7
diff -c -r1.7 RandomAccessFile.java
*** java/io/RandomAccessFile.java       24 Jul 2002 17:48:41 -0000      1.7
--- java/io/RandomAccessFile.java       7 Aug 2002 17:25:20 -0000
***************
*** 171,177 ****
  
    public int skipBytes (int count) throws IOException
    {
!     return count <= 0 ? 0 : fd.seek(count, FileDescriptor.CUR, true);
    }
  
    public void write (int oneByte) throws IOException
--- 171,181 ----
  
    public int skipBytes (int count) throws IOException
    {
!     if (count <= 0)
!       return 0;
!     long startPos = fd.getFilePointer();
!     long endPos = fd.seek(count, FileDescriptor.CUR, true);
!     return (int) (endPos - startPos);
    }
  
    public void write (int oneByte) throws IOException
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]