Skip to content

FR: ensure users who catch InterruptedException also call Thread.currentThread().interrupt() #1043

@iamdanfox

Description

@iamdanfox

What happened?

It's easy for people to write code like this with no failures:

} catch (InterruptedException e) {
  throw new RuntimeException(e);
}

Just rethrowing an exception like this is usually wrong because if the user is trying to abort, the calling thread will be unable to detect that an interruption happened and short-circuit.

What did you want to happen?

For the cases where people are re-throwing some unchecked exception, error-prone should suggest:

 } catch (InterruptedException e) {
+    Thread.currentThread().interrupt();
     throw new RuntimeException(e);
 }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions