Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java File.setWritable() and stopped working correctly after JDK 6u18

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.

like image 383
Jim Tough Avatar asked Mar 14 '11 17:03

Jim Tough


1 Answers

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.

like image 79
Dan Berindei Avatar answered Oct 21 '22 16:10

Dan Berindei