mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 10:37:59 +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:
parent
594d2f5238
commit
2c83c73005
1 changed files with 6 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue