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

File.listFiles() requires null check on return value - should have better error handling

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.1
    • core-libs
    • generic
    • generic

      Name: gm110360 Date: 09/21/2001


      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)


      The various listFiles methods of File all have the following annoying feature:
      they may possibly return null if an I/O error occurs.

      This behavior of listFiles is very inconvenient, because it means that not only
      must I have code that handles IOExceptions (which is fine), but I also have to
      do additional null checks on the result.

      Better behavior would be that if an I/O error occurs, than an IOException always
      gets thrown. You should not use a distinguished return value to sometimes
      indicate errors, and then also other times throw Exceptions!

      (Note: the other time that null can be retuned from listFiles is if the path is
      not a directory. It would probably be better behavior to always thru an
      Exception in this case too instead of returning null.)
      (Review ID: 132377)
      ======================================================================

            alanb Alan Bateman
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: