harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Richard Liang" <richard.lian...@gmail.com>
Subject Re: [classlib][io][nio] Sync issue of java.io.FileOutputStream and java.nio.channels.FileChannel
Date Wed, 20 Sep 2006 01:41:52 GMT
On 9/19/06, Andrew Zhang <zhanghuangzhu@gmail.com> wrote:
> On 9/18/06, Richard Liang <richard.liangyx@gmail.com> wrote:
> >
> > Hello,
> >
> > One Apache Derby test[1] fails on Harmony. It seems that RI always
> > sync the FileOutputStream and FileChannel after each "write", which is
> > different from Harmony. But there is no explicit description in Java
> > Spec. Shall we follow RI? Thanks a lot.
> >
> > The following test cases could demonstrate this issue.
> >
> >    public void testFile() {
> >        File derbyLog = new File("d:\\", "derby1.log");
> >
> >        try {
> >            FileOutputStream fos = new FileOutputStream(derbyLog);
> >            fos.write(0x41);
> >            assertEquals(1, derbyLog.length());
> >        } catch (Exception e) {
> >            e.printStackTrace();
> >        }
> >    }
> >
> >    public void testFileChannel() {
> >        File derbyLog = new File("d:\\", "derby2.log");
> >
> >        try {
> >            FileOutputStream fos = new FileOutputStream(derbyLog);
> >            FileChannel fc = fos.getChannel();
> >            fc.write(ByteBuffer.wrap(new byte[]{0x41, 0x42}));
> >            assertEquals(2, derbyLog.length());
> >        } catch (Exception e) {
> >            e.printStackTrace();
> >        }
> >    }
>
>
> Richard, we're fooled by "derbyLog.length()". :-) That's the root of evil!
>
> Harmony uses "FindFirstFile" to get file attribute, which may not be latest
> information of file. MSND points out "In rare cases, file attribute
> information on NTFS file systems may not be current at the time you call
> this function." That's why the test failed against Harmony. If using
> "GetFileAttributeEx" instead, the test passes against Harmony. :-)   But I
> don't think the test is theoretically stable, since the file is not opened
> with "sync" flag. :-) We could use RandomAccessFile("file","rwd(s)") for
> test.  Let's file a JIRA and fix it!

Thank you very much, Andrew. I have raised a JIRA [1] for this issue.

[1] https://issues.apache.org/jira/browse/HARMONY-1497

>
> [1]
> > http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/logStream.java?view=co
> > --
> > Richard Liang
> > China Development Lab, IBM
> >
> > ---------------------------------------------------------------------
> > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> >
> >
>
>
> --
> Andrew Zhang
> China Software Development Lab, IBM
>
>


-- 
Richard Liang
China Development Lab, IBM

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message