...
Wiki Markup |
---|
Any callers higher up in the call stack are unable to determine that an interrupted exception occurred and act on it \[[Goetz 2006|AA. Java References#GoetzBibliography#Goetz 06]\]. |
Compliant Solution
This compliant solution catches the InterruptedException
and restores the interrupted status by calling the interrupt()
method on the current thread.
...
Wiki Markup |
---|
Consequently, code that is higher up on the call stack can see that an interrupt was issued \[[Goetz 2006|AA. Java References#GoetzBibliography#Goetz 06]\]. |
Exceptions
EX1: It is reasonable to ignore handling an exception that occurs within a catch
or finally
block, such as when closing a FileInputStream
object.
...
Wiki Markup |
---|
*EX3:* "The only situation in which it is acceptable to swallow an interrupt is when you are extending Thread and therefore control all the code higher up on the call stack." \[[Goetz 2006|AA. Java References#GoetzBibliography#Goetz 06]\]. In such cases {{InterruptedException}} may be caught and ignored. A interruption request may also be swallowed by code that implements a thread's interruption policy \[[Goetz 2006, pg 143|AA. Java References#GoetzBibliography#Goetz 06]\]. |
Risk Assessment
Ignoring or suppressing exceptions violates the fail-safe criteria of an application.
...
Wiki Markup |
---|
\[[JLS 2005|AA. Java References#JLSBibliography#JLS 05]\] [Chapter 11, Exceptions|http://java.sun.com/docs/books/jls/third_edition/html/exceptions.html] \[[Bloch 2008|AA. Java References#BlochBibliography#Bloch 08]\] Item 65: "Don't ignore exceptions", Item 62: "Document all exceptions thrown by each method" \[[Goetz 2006|AA. Java References#GoetzBibliography#Goetz 06]\] 5.4 Blocking and interruptible methods \[[MITRE 2009|AA. Java References#MITREBibliography#MITRE 09]\] [CWE ID 390|http://cwe.mitre.org/data/definitions/390.html] "Detection of Error Condition Without Action" |
...