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

(file) Re-examine DirectoryStream exception handling

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7
    • 7
    • core-libs
    • b112
    • generic, x86
    • generic, windows_2008
    • Verified

      This bug is tracking the following issues with DirectoryStream:

      1. The iterator's hasNext/next methods cannot throw checked exceptions and so must throw a CME with the IOException as the cause when an I/O error is encountered during iteration. This is confusing to developers and requires code to catch and pull out the IOException. We can improve the API by introducing specialized CME (DirectoryIteratorException). Its getCause method can be override to return an IOException to avoid needing to distinguish IOException from other possible causes.

      2. Similiar to 1, the case where hasNext/next are invoked after the directory stream has been closed should be re-exmained.

      3. The iterator remove method is painful in that it needs to handle both I/O errors and possible security exceptions. The simplest solution is to just change it to throw UnsupportedOperationException. Applications that wish to delete files during the directory iteration can invoke the Path delete method.

            alanb Alan Bateman
            alanb Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: