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

Optional.map() javadoc code example is incorrect

XMLWordPrintable

    • b145
    • generic
    • generic
    • Not verified

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      Is the example in API Note for map method on Optional class correct?
      https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#map-java.util.function.Function-

           Optional<FileInputStream> fis =
               names.stream().filter(name -> !isProcessedYet(name))
                             .findFirst()
                             .map(name -> new FileInputStream(name));

      new FileInputStream(name) in the map function throws java.io.FileNotFoundException (checked exception)


      REPRODUCIBILITY :
      This bug can be reproduced always.

            psandoz Paul Sandoz
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: