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

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

问题描述

我们有一个带有特定模块的 Java 应用程序,该模块在执行其功能之前检查临时目录是否可写".为了测试这一点,我们有一个 JUnit 测试,它创建一个新目录,使用 Java File 类方法 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天全站免登陆