Skip to content

instanceof / BC_IMPOSSIBLE_INSTANCEOF false positive in catch block #926

@rjclark

Description

@rjclark

I'm seeing what I think is false positive in this code block

try {
   ...
}
catch (Exception e) {
    if ( e instanceof InterruptedException ) { // <- false positive
        ...
    }
}

instanceof will always return false
This instanceof test will always return false. Although this is safe, make sure it isn't an indication of some misunderstanding or some other logic error.

Bug kind and pattern: BC - BC_IMPOSSIBLE_INSTANCEOF

instanceof will always return false in [...], since a RuntimeException can't be a InterruptedException

It appears as through the Exception is being turned into a RuntimeException incorrectly, before analysis.

This also appears to have been reported against Findbugs:

https://sourceforge.net/p/findbugs/bugs/1463/

I've seen the same problem with IntelliJ's inspections

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions