Friday, May 4, 2012

Find the bug - part 3 (Windows edition)

I have come across a strangeness with Java on Windows with regards to file handling, i.e. the following code:

The code works fine on Linux, but on Windows it complains that the "from" file cannot be deleted, when the file is supposed to be moved using the Google Guava Files.move(File from, File to) method. There is a very subtle thing one has to do to get it to work on Windows. What is it?

Post your answers in the comments and then I will let you know after a while :)

3 comments:

  1. Yip, lock indeed... however, I still think the code is at fault here.  It just does not feel right to move an open file around... or is it? Hmmm..., maybe the Microsoft cancer in my brain is not gone yet... :-)

    ReplyDelete
  2. Also, look at all that mutable state......

    ReplyDelete
  3. The linux filesystem says: "I'll allow it".

    ReplyDelete