Unverified / unconfirmed listing using generics general restrictions

The following code causes a "Unverified / Unapproved Casting" critical violation using Sonar + FindBugs:

1    public static <P extends ComponentContainer & AlignmentHandler> void addComponentAligned(P parent, Component child, Alignment alignment) {
2        parent.addComponent(child);
3        parent.setComponentAlignment(child, alignment);
4    }

Any ideas on how to avoid this violation?

EDIT: Violation is on line 3

EDIT: Method signatures follow: ComponentContainer # addComponent (Component) Alignment Handler # setComponentAlignment (Component, Alignment)

+5
source share
1 answer

There is no fill in the source code, but there is a compilation in the bytecode. In bytecode, common types are erased. For erasing Pis its first boundary ComponentContainer. Thus, the bytecode is (almost) equivalent to the bytecode:

public static void addComponentAligned(ComponentContainer parent, Component child, Alignment alignment) {
    parent.addComponent(child);
    ((AlignmentHandler)parent).setComponentAlignment(child, alignment);
}

Findbugs - , AlignmentHandler , ( findbugs) ComponentContainer.

findbugs; . , . - () , findbugs .

+5

All Articles