fb-contrib
fb-contrib copied to clipboard
false-positive for ITC_INHERITANCE_TYPE_CHECKING in overridden method
I implement a method in an interface that is not under my control.
This method needs to do instanceof
checks on the parameter to decide how to handle the event.
I don't see any chance besides reflection to do this in another way.
If the instanceof
checks are done on the parameter of an @Override
-annotated method, this rule should not report a violation.
Can you give a code example?
@Override isn't really the key point, it's that you don't own the package of the interface. I agree with your assessment, tho, but won't be all that easy to fix. In the interim, you can use the SuppressFBWarnings annotation.
Sure @ThrawnCA:
@Override
public void onEvent(GenericEvent event) {
if (event instanceof MessageReceivedEvent) {
onMessageReceived((MessageReceivedEvent) event);
} else if (event instanceof PrivateMessageReceivedEvent) {
onPrivateMessageReceived((PrivateMessageReceivedEvent) event);
}
}
You're right of course Dave, that if you control the interface, you could change the signature there.
i'm assuming that MessageReceivedEvent and PrivateMessageReceiveEvent are not yours, if they were, you could just have them implement an interface like
interface VampireEvent {
public void processEvent();
}
and just then do
public void onEvent(GenericEvent event) {
VampireEvent ve = (VampireEvent) event;
ve.processEvent();
}
Yes, of course not, they are from the same lib as the interface. In this case it is JDA.