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

com/sun/org/apache/xerces/internal/xinclude/XIncludeHandler.java manually leave `finally` block, discarding exception

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Some JDK classes use statements such as `return` or `continue` in the `finally` block of a `try` statement. If an exception is thrown in the body of the `try` statement, the `finally` block silently discards it in this case.
      Here is a simplified example:
      switch (1) {
          default -> {
              try {
                  throw new Error();
              } finally {
                  yield 1;
              }
          }
      }

      Affected JDK classes:
      - https://github.com/openjdk/jdk/blob/83b6e4bc04db89a846a1b6c2d0666efe139f8f61/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xinclude/XIncludeHandler.java#L1940


      Ideally the compiler would detect this and warn about it, or even prevent such code.

      (This was detected by https://github.com/github/codeql/blob/main/java/ql/src/Violations%20of%20Best%20Practice/legacy/FinallyMayNotComplete.ql)


            joehw Joe Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: