commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Filip Defoort <filip...@cirquedigital.com>
Subject Re: [VFS] NPE in rename()
Date Fri, 21 Jul 2006 14:56:26 GMT
Great, thanks a lot.

I have a more complicated case now (the one I was starting to build :-D 
): rename to the same file,
but different case. That's bad, since it actually deletes the source 
file...:

import java.io.*;
import org.apache.commons.vfs.*;
import org.apache.commons.vfs.impl.*;

public class RenameCase {


   public static final void main(final String[] args) throws Exception {

            StandardFileSystemManager fileSystemManager
                 = new StandardFileSystemManager();

            fileSystemManager.setCacheStrategy(CacheStrategy.ON_RESOLVE);
            fileSystemManager.init();

            FileSystemOptions fileoptions = new FileSystemOptions();
            FileObject root = fileSystemManager.resolveFile("/tmp/", 
fileoptions);

            File dummy = new File("/tmp/test.txt");
            dummy.createNewFile();

            Writer w = new FileWriter(dummy);
            w.write("Some text");
            w.close();

            long size = dummy.length();

            FileObject fo = root.resolveFile("test.txt");
            FileObject fo2 = root.resolveFile("TeST.txt");

            System.out.println("fo = " + fo);
            System.out.println("fo2 = " + fo2);

            fo.moveTo(fo2);


   }

}

fo = file:///tmp/test.txt
fo2 = file:///tmp/TeST.txt
Exception in thread "main" org.apache.commons.vfs.FileSystemException: 
Could not rename "file:///tmp/test.txt" to "file:///tmp/TeST.txt".
        at 
org.apache.commons.vfs.provider.AbstractFileObject.moveTo(AbstractFileObject.java:950)
        at RenameCase.main(RenameCase.java:34)
Caused by: org.apache.commons.vfs.FileSystemException: Could not rename 
file "/tmp/test.txt" to "file:///tmp/TeST.txt".
        at 
org.apache.commons.vfs.provider.local.LocalFile.doRename(LocalFile.java:134)
        at 
org.apache.commons.vfs.provider.AbstractFileObject.moveTo(AbstractFileObject.java:936)
        ... 1 more

After this, neither file exists anymore.... That could cause some major 
head-aches...

Cheers,
- Filip


Mario Ivankovits wrote:
> Hi Filip!
>   
>> I might just be getting tired now, but the following test fails
>> with a NPE:
>>     
> ;-)
> This was due to the fixes I did for the threading issue - and unhappily
> I didnt had the time to run the tests.
> But its fixed now.
>
> Sorry for the inconvenience.
>
> Ciao,
> Mario
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message