RFR (13) [testbug]: 8227422: sun/net/www/protocol/file/DirPermissionDenied.java failed on Windows 2016 because DirPermissionDenied directory has no read permission

Daniel Fuchs daniel.fuchs at oracle.com
Wed Jul 10 13:25:13 UTC 2019


Hi Franck, Vyom,

On 10/07/2019 08:34, Vyom Tewari26 wrote:
> that's what i suspected, but test is passing at my local env  even after 
> i changes the permission to 733.
> Vyom

Argh!

Of course, the test should ideally throw an AssertionError if
the expected exception is not raised.
And you will discover that chmod doesn't work on windows:

Something like this seems to be missing:

@@ -54,6 +54,7 @@
          try {
              URLConnection uc = url.openConnection();
              uc.connect();
+            throw new AssertionError("connect should have failed");
          } catch (IOException e) {
              // OK
          } catch (Exception e) {
@@ -63,6 +64,7 @@
          try {
              URLConnection uc = url.openConnection();
              uc.getInputStream();
+            throw new AssertionError("getInputStream should have failed");
          } catch (IOException e) {
              // OK
          } catch (Exception e) {
@@ -72,8 +74,6 @@
          try {
              URLConnection uc = url.openConnection();
              uc.getContentLengthLong();
-        } catch (IOException e) {
-            // OK
          } catch (Exception e) {
              throw new RuntimeException("Failed " + e);
          }

But if you do that - then the test will consistently fail on
windows. Maybe we should do it though, and add an @require
tag to skip windows... Or use the java.nio.files APIs with
PosixAttributeView [2] (if supported) or ACL view [3] (if posix
is not available) to change the file readability instead
of using chmod...

Side note: the length of the file can be obtained even if the directory
is not readable:

$ mkdir ~/test/notreadable
$ chmod 333 ~/test/notreadable

$ ls -l ~/test | grep notr
d-wx-wx-wx+  2 dfuchs  owner        68 Jul 10 10:43 notreadable

$ ls -l ~/test/notreadable
ls: notreadable: Permission denied

As per [1] the issue was that sometimes a NPE was thrown, so for
getContentLengthLong() it is enough to verify that no stray
exception is thrown - which the test does adequately.

best regards,

-- daniel

[1] https://bugs.openjdk.java.net/browse/JDK-6977851
[2] 
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/attribute/PosixFileAttributeView.html
[3] 
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/attribute/AclFileAttributeView.html


More information about the net-dev mailing list