mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +01:00
[core] Use XmppElementUtil.castOrThrow() in StanzaView.getExtension(Class)
This means that users get now exceptions with helpful error messages instead of the dreaded ClassCastException, like java.lang.ClassCastException: org.jivesoftware.smack.packet.StandardExtensionElement cannot be cast to org.jivesoftware.smackx.mam.element.MamElements$MamResultExtension at when StanzaView.getExtension(Class) is used to retrieve the extension.
This commit is contained in:
parent
d06e9499e8
commit
b09cd06053
1 changed files with 3 additions and 2 deletions
|
@ -90,11 +90,12 @@ public interface StanzaView extends XmlLangElement {
|
|||
default <E extends ExtensionElement> E getExtension(Class<E> extensionElementClass) {
|
||||
QName qname = XmppElementUtil.getQNameFor(extensionElementClass);
|
||||
ExtensionElement extensionElement = getExtension(qname);
|
||||
if (!extensionElementClass.isInstance(extensionElement)) {
|
||||
|
||||
if (extensionElement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return extensionElementClass.cast(extensionElement);
|
||||
return XmppElementUtil.castOrThrow(extensionElement, extensionElementClass);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue