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

HttpRequest.BodyPublishers#ofFile(Path) assumes the default file system

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 15
    • core-libs
    • None
    • behavioral
    • minimal
    • Java doc change only to clarify behaviour
    • Java API
    • SE

      Summary

      Specify a file system related constraint in the existing @throws declaration of HttpRequest.BodyPublisher::ofFile.

      Problem

      The original specification of BodyPublisher::ofFile assumed that the given path belongs to the default file system or behaves as such, and would fail if this was not the case. A fix is proposed to enable BodyPublisher::ofFile to work with other file system path implementations. Accordingly, a specification change should clarify when a SecurityException is thrown, depending on the file system of the given path.

      Solution

      Specify the conditions of when a SecurityException is thrown, which is only in the case of the system-default file system provider.

      Specification

      java.net.http.HttpRequest.BodyPublishers

       -    * @throws SecurityException if a security manager has been installed
       -    *          and it denies {@link SecurityManager#checkRead(String)
       -    *          read access} to the given file
       +    * @throws SecurityException if opening the file for reading is denied:
       +    *         in the case of the system-default file system provider, and
       +    *         a security manager is installed,
       +    *         {@link SecurityManager#checkRead(String) checkRead}
       +    *         is invoked to check read access to the given file
            */
           public static BodyPublisher ofFile(Path path) throws FileNotFoundException {

            jboes Julia Boes (Inactive)
            webbuggrp Webbug Group
            Chris Hegarty, Daniel Fuchs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: