#1240 False positive BC_UNCONFIRMED_CAST with multiple generics

3.x
open-accepted
William Pugh
5
2014-06-19
2014-01-09
No

Steps to reproduce:
1. Expand the attached .tgz file.
2. Edit build.xml and point findbugs-home at a FindBugs installation.
3. ant findbugs.
4. Produces findbugs.xml with one bug reported.

The 'bug' is supposedly an unconfirmed cast on line 5 of Renderer.java. FindBugs claims that value is an Enum, and therefore we can't call a method from Displayable without an implied cast.

However, the generics in the definition of the type param T at the beginning of the class state that T extends Enum<T> & Displayable, and therefore the value passed into the method in question must be both an Enum and a Displayable -- therefore calling the method from Displayable is safe.

By comparison, doing exactly the same thing with FindBugs 1.3.9 does not produce any bug warnings.

Java Versions: reproduced with both 1.7.0_45 and 1.6.0_65
OS: Mac OS X 10.8.5

1 Attachments

Discussion

  • William Pugh
    William Pugh
    2014-01-09

    • labels: --> false positive
    • status: open --> open-accepted
    • assigned_to: William Pugh
    • Group: 2.0.3 --> 3.0.0
     
  • William Pugh
    William Pugh
    2014-01-09

    Reproduced as a low priority warning, correct?

     
    • Yes, that's right -- as with [#1242], not a very common scenario, but I felt worth logging given the change in behaviour from 1.3.9.

      Thanks William,

      David

       

      Related

      Bugs: #1242

    • Group: 3.0.0 --> 3.0.1