- Versions:
** Sonarqube 7.9.1 (build 27448),
** Gradle Sonar plugin id “org.sonarqube” version "2.8"
- Description:
When calling Thread.sleep(...)
you need to handle InterruptedException
. Catching it will cause the above mentioned rule to raise an issue that describes to rethrow or call Thread.currentThread().interrupt()
.
As any part in a try-catch-block
should be a oneliner, exception handling and the proposed call are within a called method. But the rule still raises an issue.
- Example:
private static void waitForNextExecution(Set<Task> running, LongSupplier waitTimeoutMillis) {
try {
Thread.sleep(waitTimeoutMillis.get());
} catch (InterruptedException e) {
cancelAllSubTasksAndInterrupt(running);
}
}
private static void cancelAllSubTasksAndInterrupt(Set<Task> subTasks) {
for (Task task : subTasks) {
String key = task.getName();
LOG.info("--- waitForNextExecution: Service interrupted. Cancel execution of task {}.", key);
task.cancel(true);
}
Thread.currentThread().interrupt();
}