harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikhail Markov (JIRA)" <j...@apache.org>
Subject [jira] Updated: (HARMONY-3324) [classlib][nio] It is not possible to delete file after transferring data from it
Date Thu, 29 Mar 2007 13:32:26 GMT

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

Mikhail Markov updated HARMONY-3324:
------------------------------------

    Attachment: H-3324.patch

Here is the fix for the issue + regression tests.

Fix description:
1) transferTo() and transferFrom() methods of FileChannelImpl are using map() function which
prevents file from being deleted (note, that RI also could not delete the file after map()
method was called). So, the memory should be unmaped at the end of these methods as it is
used for the methods purposes only. I've used free() method to do the unmapping operations.
2) It seems that there was a bug in java.nio.MappedByteBufferAdapter.free() method which first
frees the memory by itself bypassing DirectByteBuffer.free() method and only after that calling
this method. As a result the following error was printed: "Memory Spy! Fixed attempt to free
memory that was not allocated PlatformAddress[31981568]". Comments for DirectByteBuffer.free()
method clearly says that "Note this is is possible that the memory is freed by code that reaches
into the address and explicitly frees it 'beneith' us -- this is bad form.". So i've remove
the explicit freeing of the memory in MappedByteBufferAdapter.free() method.

> [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
>         Attachments: H-3324.patch
>
>
> 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.


Mime
View raw message