You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Alexey Varlamov (JIRA)" <ji...@apache.org> on 2007/03/12 07:38:09 UTC

[jira] Updated: (HARMONY-3324) [classlib][nio] It is not possible to delete file after transferring data from it

     [ https://issues.apache.org/jira/browse/HARMONY-3324?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexey Varlamov updated HARMONY-3324:
-------------------------------------

    Component/s: Classlib

> [classlib][nio] It is not possible to delete file after transferring data from it
> ---------------------------------------------------------------------------------
>
>                 Key: HARMONY-3324
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3324
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Vera Petrashkova
>
> When FileChannel was object was associated with some File
> File.delete always returns false after transferring data from this file to another.
> To reproduce this issue run the following test:
> ----------testFileChannel.java-------------------
> import java.io.*;
> import java.nio.channels.FileChannel;
> import java.nio.ByteBuffer;
> public class testFileChannel {
>     public static void main (String[] argv) {        
>         boolean isTrans = (argv.length > 0);
>         int whatFrom = 0;
>         if (isTrans) {
>             whatFrom = Integer.parseInt(argv[0]);
>         }
>         FileChannel from = null;
>         FileChannel to = null;
>         File f = null;
>         File f1 = null;
>         boolean fDel = true;
>         boolean f1Del = true; 
>         try {
>             f = new File("from.txt");
>             if (f.exists()) {
>                 System.err.println("Delete from.txt : "+f.delete());
>             }
>             f1 = new File("to.txt");
>             if (!f1.exists()) {
>                 f1.createNewFile();
>             }
>             try {
>                 from = new FileOutputStream(f).getChannel(); 
>                 byte [] b = {(byte)1, (byte)2};
>                 ByteBuffer bb = ByteBuffer.allocateDirect(b.length).wrap(b);
>                 from.write(bb);              
>                 from.force(false);
>             } catch (Throwable e) {
>                 System.err.println("Unexpected error");
>                 e.printStackTrace();
>                 return;
>             } finally {
>                 if (from != null) {
>                     from.close();
>                 }
>             }
>             to = null;
>             from = null;
>             try {
>                 from = new FileInputStream(f).getChannel(); 
>                 to = new FileOutputStream(f1).getChannel(); 
>                 if (isTrans) {
>                     long pp = (whatFrom == 0 ? from.transferTo(0 , 2,  to) : to.transferFrom(from, 0 , 2)); 
>                 }
>             } catch (Throwable e) {
>                 e.printStackTrace();
>             } finally {
>                 if (from != null) {
>                     from.close();
>                 }
>                 if (to != null) {
>                     to.close();
>                 }
>             }
>         } catch (Throwable e) {
>             e.printStackTrace();
>         } finally {
>             if (f != null) {
>                 fDel = f.delete();
>             }
>             if (f1 != null) {
>                 f1Del = f1.delete();
>             }
>         }
>         if (!fDel) {
>             System.err.println("File "+f+" exists: "+f.exists());
>         }
>         if (!f1Del) {
>             System.err.println("File "+f1+" exists:  "+f1.exists());
>         }
>         if (!fDel || !f1Del) {
>             System.err.println("Test failed");
>             return;
>         }
>         System.err.println("Test passed"); 
>     }
> }
> --------------------
> Test passes when java.nio.FileChannel.transferTo[transerFrom] is not invoked.
> But it fails when one of these methods is used.
> java -cp . testFileChannel 
> Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or its l
> icensors, as applicable.
> java version "1.5.0"
> pre-alpha : not complete or compatible
> svn = r515167, (Mar  7 2007), Windows/ia32/msvc 1310, release build
> http://incubator.apache.org/harmony
> Test passed
> java -cp . testFileChannel 0
> java -cp . testFileChannel 1
> Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or its l
> icensors, as applicable.
> java version "1.5.0"
> pre-alpha : not complete or compatible
> svn = r515167, (Mar  7 2007), Windows/ia32/msvc 1310, release build
> http://incubator.apache.org/harmony
> File from.txt exists: true
> Test failed
> This issue causes the failure of the following reliability test: 
>     api.nio.channels.filechannel.CopyFilesTest
> Reliability test repeatedly tries to create temporary file, write some data to it, copy information to another files and delete the first file.
> It fails on the second iteration.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.