Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8062795

(fs) Files.setPermissions requires read access when NOFOLLOW_LINKS specified

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 22
    • 7u72, 8u40
    • core-libs
    • b12
    • x86_64
    • linux_ubuntu, os_x
    • Verified

    Description

      FULL PRODUCT VERSION :
      java version "1.7.0_72"
      Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux chimay 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Calling PosixFileAttributeView.setPermissions() on a file which has write but no read permission throws an AccessDeniedException iff LinkOption.NOFOLLOW_LINKS is passed. Without the option it works fine.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the executable test case below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected output would be as below, without any exceptions.

      first setPermissions()
      second setPermissions()
      third setPermissions()
      fourth setPermissions()

      ACTUAL -
      The actual output is below. The fourth and final setPermission() call throws an AccessDeniedException.

      first setPermissions()
      second setPermissions()
      third setPermissions()
      fourth setPermissions()
      Exception in thread "main" java.nio.file.AccessDeniedException: /tmp/bar8340250403048004139.tmp
      at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
      at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
      at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
      at sun.nio.fs.UnixPath.openForAttributeAccess(UnixPath.java:787)
      at sun.nio.fs.UnixFileAttributeViews$Posix.setMode(UnixFileAttributeViews.java:220)
      at sun.nio.fs.UnixFileAttributeViews$Posix.setPermissions(UnixFileAttributeViews.java:250)
      at com.datadobi.n2n.distributed.nfsproxy.handlers.Example.main(Example.java:30)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.nio.file.AccessDeniedException: /tmp/bar8340250403048004139.tmp
      at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
      at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
      at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
      at sun.nio.fs.UnixPath.openForAttributeAccess(UnixPath.java:787)
      at sun.nio.fs.UnixFileAttributeViews$Posix.setMode(UnixFileAttributeViews.java:220)
      at sun.nio.fs.UnixFileAttributeViews$Posix.setPermissions(UnixFileAttributeViews.java:250)
      at com.datadobi.n2n.distributed.nfsproxy.handlers.Example.main(Example.java:30)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.IOException;
      import java.nio.file.Files;
      import java.nio.file.LinkOption;
      import java.nio.file.Path;
      import java.nio.file.Paths;
      import java.nio.file.attribute.PosixFileAttributeView;
      import java.nio.file.attribute.PosixFilePermission;
      import java.util.Collections;

      public class Example
      {
          public static void main(String[] args) throws IOException
          {
              Path fooPath = Files.createTempFile(Paths.get("/tmp"), "foo", ".tmp");

              PosixFileAttributeView fooView = Files.getFileAttributeView(fooPath, PosixFileAttributeView.class);
              System.err.println("first setPermissions()");
              fooView.setPermissions(Collections.singleton(PosixFilePermission.OWNER_WRITE));
              System.err.println("second setPermissions()");
              fooView.setPermissions(Collections.singleton(PosixFilePermission.OWNER_WRITE));

              Path barPath = Files.createTempFile(Paths.get("/tmp"), "bar", ".tmp");

              PosixFileAttributeView barView = Files.getFileAttributeView(barPath, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
              System.err.println("third setPermissions()");
              barView.setPermissions(Collections.singleton(PosixFilePermission.OWNER_WRITE));
              System.err.println("fourth setPermissions()");
              barView.setPermissions(Collections.singleton(PosixFilePermission.OWNER_WRITE));
          }
      }

      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              bpb Brian Burkhalter
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: