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

Revisit (Doc)Tree search implemented by throwing an exception

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 19
    • 17
    • tools
    • None
    • b20

      In the below case a tree is searched for a specific node: https://github.com/openjdk/jdk/blob/739769c8fc4b496f08a92225a12d07414537b6c0/src/jdk.compiler/share/classes/com/sun/source/util/DocTreePath.java#L61

      If the node is found, the search is terminated by throwing an exception containing that node: https://github.com/openjdk/jdk/blob/739769c8fc4b496f08a92225a12d07414537b6c0/src/jdk.compiler/share/classes/com/sun/source/util/DocTreePath.java#L77

      The exception is then caught and the contained node is returned as the result of the search: https://github.com/openjdk/jdk/blob/739769c8fc4b496f08a92225a12d07414537b6c0/src/jdk.compiler/share/classes/com/sun/source/util/DocTreePath.java#L90

      Such use of exceptions is counterintuitive and should be avoided. (See, for example, Item 69: Use exceptions only for exceptional conditions; Effective Java, Third Edition)

      For the record: "make docs-jdk-api" results in approximately 220,000 of such exceptions being created and thrown.

            jjg Jonathan Gibbons
            prappo Pavel Rappo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: