-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
17
-
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)
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)
- is cloned by
-
JDK-8281708 sun/awt/X11/XWindowPeer.java manually leave `finally` block, discarding exception
-
- Open
-
-
JDK-8281703 sun/nio/ch/SocketChannelImpl.java manually leave `finally` block, discarding exception
-
- Closed
-
-
JDK-8281709 sun/tools/jps/Jps.java manually leave `finally` block, discarding exception
-
- Closed
-