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

sun/tools/jps/Jps.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/jdk.jcmd/share/classes/sun/tools/jps/Jps.java#L157


      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)


            kevinw Kevin Walls
            tongwan Andrew Wang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: