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

妖精的绣舞 提交于 2019-12-19 03:36:18

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5302269/java-file-setwritable-and-stopped-working-correctly-after-jdk-6u18

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!