1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-22 20:47:57 +01:00

core: Avoid ClassCastException in getExtension(Class)

Ensure that he returned extension element is actually of the correct
type. It should not be common, but in theory, Smack's provider
architecture would allow for different types to be returned than the
ones one may expect.
This commit is contained in:
Florian Schmaus 2020-04-11 18:04:15 +02:00
parent 594d2f5238
commit 2c83c73005

View file

@ -87,10 +87,14 @@ public interface StanzaView extends XmlLangElement {
return false;
}
@SuppressWarnings("unchecked")
default <E extends ExtensionElement> E getExtension(Class<E> extensionElementClass) {
QName qname = XmppElementUtil.getQNameFor(extensionElementClass);
return (E) getExtension(qname);
ExtensionElement extensionElement = getExtension(qname);
if (!extensionElementClass.isInstance(extensionElement)) {
return null;
}
return extensionElementClass.cast(extensionElement);
}
/**