Hello,
First off, I'm new to posting here, greetings everyone!
So, Rule S2142 ("InterruptedException" should not be ignored) has
been very handy for the various multi-threaded projects I work on. However, it
doesn't seem to detect the following case.
Incorrect Code:
try
{
throwsException();
throwsInterruptedException();
}
catch (Exception e)
{
LOGGER.error("An error occurred.", e);
return null; // Or throw e; etc...
// If e is an InterruptedException we need to re-interrupt...
oops!
}
Correct Code:
try
{
throwsException();
throwsInterruptedException();
}
catch (InterruptedException e)
{
LOGGER.debug("Interrupted");
Thread.currentThread().interrupt();
}
catch (Exception e)
{
LOGGER.error("An error occurred.", e);
return null; // Or throw e; etc...
}
Code similar in pattern to this is fairly common for my projects due to
interfaces, legacy code, and 3rd party code declaring methods that throw
Exception. Is this something that rule S2142 should be updated to check? Or
should a new rule be created for this? Or does this fall into the category of a
custom rule I should write just for my SonarQube instance?
Thank You,
Austin