You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Filip Defoort <fi...@cirquedigital.com> on 2006/07/21 15:39:45 UTC

[VFS] NPE in rename()

Hi VFS,

I might just be getting tired now, but the following test fails
with a NPE:

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("test2.txt");

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

            fo.moveTo(fo2);

   }

fo = file:///tmp/test.txt
fo2 = file:///tmp/test2.txt
Exception in thread "main" java.lang.NullPointerException
        at 
org.apache.commons.vfs.provider.local.LocalFile.doRename(LocalFile.java:132)
        at 
org.apache.commons.vfs.provider.AbstractFileObject.moveTo(AbstractFileObject.java:930)
        at RenameCase.main(RenameCase.java:34)


Can anybody spot what I'm missing ?

Thanks,
- Filip



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


Re: [VFS] NPE in rename()

Posted by Filip Defoort <fi...@cirquedigital.com>.
Mario Ivankovits wrote:
> Hi!
>   
>> it's _physically_ lost; the code deletes the target file first...
>>     
> Oh yes, I am an idiot, I've overlooked it, sorry.
>   
:-D...
> Hmmm ... I'll think about it.
>
> OSX is NOT case sensitive?
>   
Depends on which file system, but by default no, it's not... (not their 
smartest choice
I might say).

Thanks a lot,
- Filip

> 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


Re: [VFS] NPE in rename()

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
> it's _physically_ lost; the code deletes the target file first...
Oh yes, I am an idiot, I've overlooked it, sorry.

Hmmm ... I'll think about it.

OSX is NOT case sensitive?

Ciao,
Mario


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


Re: [VFS] NPE in rename()

Posted by Filip Defoort <fi...@cirquedigital.com>.
Mario Ivankovits wrote:
>
>> After this, neither file exists anymore.... That could cause some
>> major head-aches...
>>     
> Works here (on linux) you are on windows, no?
>   
right now testing on OSX; but across linux/windows/osx most of the time.
The idea is to be able to rename the case of a file.. (even if in some cases
the FS itself is not case sensitive; but case preserving).
> Do you mean, the file is physically lost, or only logical in the FileObject.
> If its physical lost, then I'd please you to check it using plain
> java.io.File.renameTo - VFS should not delete the file.
>   
it's _physically_ lost; the code deletes the target file first...
> Maybe you can debug through AbstractFileObject.moveTo - it should enter
> "if (canRenameTo(destFile))" - and there is only a renameTo in the end.
> Strange.
>
> I have no windows running now, maybe on monday I should be able to check
> it myself.
>   
I'll try to dig a bit deeper to see what's going on...

Cheers,
- Filip

> 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


Re: [VFS] NPE in rename()

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi Filip!
> 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...
Works here (on linux) you are on windows, no?

Do you mean, the file is physically lost, or only logical in the FileObject.
If its physical lost, then I'd please you to check it using plain
java.io.File.renameTo - VFS should not delete the file.

Maybe you can debug through AbstractFileObject.moveTo - it should enter
"if (canRenameTo(destFile))" - and there is only a renameTo in the end.
Strange.

I have no windows running now, maybe on monday I should be able to check
it myself.

Ciao,
Mario


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


Re: [VFS] NPE in rename()

Posted by Filip Defoort <fi...@cirquedigital.com>.
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


Re: [VFS] NPE in rename()

Posted by Mario Ivankovits <ma...@ops.co.at>.
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