Java File.setWritable()并在JDK 6u18之后停止正常工作 [英] Java File.setWritable() and stopped working correctly after JDK 6u18

查看:299
本文介绍了Java File.setWritable()并在JDK 6u18之后停止正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个带有特定模块的Java应用程序,它在执行其功能之前检查临时目录是否可写。为了测试这个,我们有一个JUnit测试创建一个新目录,使用Java 文件类方法 setWritable(false)使目录不可写,然后将该目录传递给正在测试的模块,并期望返回 IllegalArgumentException 。这在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.

今天我已经将JDK版本更新为JDK 6u24(截至今天Sun网站的当前版本) )。该单元测试刚刚开始使用新的JDK失败。我在我的团队内部询问并发现其他人曾经试图在他们的机器上运行JDK 6u23并且在相同的JUnit测试中遇到同样的问题(并且只有那个测试 - 其他一切正常)。

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).

更新到较新的JDK后,是否有其他人遇到过 setWritable()方法的问题?知道如何解决这个问题吗?

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

在你问之前,我也尝试过使用 setReadonly()方法作为替代,但我得到相同的结果。

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

推荐答案

如果你在Windows上,它可能与这个错误: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6728842

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

显然 setWritable(false)从未真正用于Windows上的目录,因为readonly标志不会实际上只读一个目录。

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

这篇关于Java File.setWritable()并在JDK 6u18之后停止正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆