6

We have a Java application with a particular module that checks if a temporary directory is 'writable' before executing its function. To test this, we have a JUnit test that creates a new directory, uses the Java File class method setWritable(false) to make the directory "not writable", then passes that directory to the module being tested and expects to get an IllegalArgumentException back. This had all been working fine for a long time under JDK 6u18.

Today I have updated the JDK version to JDK 6u24 (the current release from the Sun site as of today). That unit test just started failing with the new JDK. I asked around within my team and found out that someone else had tried to run JDK 6u23 on their machine a while back and had the same problem with the same JUnit test (and only with that test - everything else works fine).

Has anyone else experienced problems with the setWritable() method after updating to a newer JDK? Any idea how to resolve this?

Before you ask, I have also tried using the setReadonly() method as an alternative, but I get the same result.

Jim Tough
  • 14,843
  • 23
  • 75
  • 96
  • yep ! it's a bug and it just got worse ! On version 7.xxx I tried to set a directory Writable, I got a success reply but ... the folder was read only. That happens on both Windows 7 and open Suse 11.4. I also checked that the bug is more than 3 years known and nobody ever fixed that. –  Jan 29 '12 at 14:06

1 Answers1

7

If you're on Windows, it's probably related to this bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6728842

Apparently setWritable(false) never really worked for directories on Windows, because the readonly flag doesn't actually make a directory readonly.

Dan Berindei
  • 7,054
  • 3
  • 41
  • 48
  • Thanks for the bug link. Sounds like this could be the source of our problem. Our module code relies on the isWritable() method and runs on Linux in production, so we're probably ok. I just need to re-write the JUnit tests (for Windows) so we don't rely on these API methods anymore. – Jim Tough Mar 14 '11 at 19:24