Smack 4.4.0-alpha3 (20200404) smack getExtension(EE.class) throws run-time IllegalArgumentException: The class e.g. Nick.java has no ELEMENT, NAMSEPACE or QNAME member. Consider adding QNAME

Following smack team latest recommendation, aTalk now uses the Stanza.java class from the master repository, and make changes to its code to use getExtension(EE.class). Most source changes work as expected, however I found that there are areas smack just throws the following errors. Below is an example where smack throws suck exception.

java.lang.IllegalArgumentException: The classclass org.jivesoftware.smackx.nick.packet.Nick has no ELEMENT, NAMSEPACE or QNAME member. Consider adding QNAME

aTalk has a private method processOtherPresence() with the mentioned exception:

What exactly is the problem and the meaning of the recommendation?
Does it means just add below statement to the affected class and no getter() i.e.

public static final QName QNAME = new QName(NAMESPACE, ELEMENT);

The other problem is that the code changes compile without any problem; the exception is thrown only during run time. Is there a way I can determine if the source changes at certain location will cause run-time problem?

        /**
         * Process a <tt>Presence</tt> packet sent by one of the other room occupants.
         */
        private void processOtherPresence(Presence presence)
        {
            ....
            Nick nickExt = presence.getExtension(Nick.class);
            if (nickExt != null) {
                member.setDisplayName(nickExt.getName());
            }
            ....
        }
============= smack exception throws on getExtension(EE.class) ============

2020-04-15 23:20:41.681 25514-25721/org.atalk.android E/aTalk: [17038] org.jivesoftware.smack.AbstractXMPPConnection.lambda$invokeStanzaCollectorsAndNotifyRecvListeners$6() Exception in packet listener
    java.lang.IllegalArgumentException: The classclass org.jivesoftware.smackx.nick.packet.Nick has no ELEMENT, NAMSEPACE or QNAME member. Consider adding QNAME
        at org.jivesoftware.smack.util.XmppElementUtil.getQNameFor(XmppElementUtil.java:52)
        at org.jivesoftware.smack.packet.StanzaView.getExtension(StanzaView.java:91)
        at net.java.sip.communicator.impl.protocol.jabber.ChatRoomJabberImpl$ParticipantListener.processOtherPresence(ChatRoomJabberImpl.java:2827)
        at net.java.sip.communicator.impl.protocol.jabber.ChatRoomJabberImpl$ParticipantListener.processPresence(ChatRoomJabberImpl.java:2721)
        at org.jivesoftware.smackx.muc.MultiUserChat$3.processStanza(MultiUserChat.java:266)
        at org.jivesoftware.smack.AbstractXMPPConnection.lambda$invokeStanzaCollectorsAndNotifyRecvListeners$6(AbstractXMPPConnection.java:1591)
        at org.jivesoftware.smack.-$$Lambda$AbstractXMPPConnection$WvFNBjGAjT0-wl3E33Swy31nrjY.run(Unknown Source:4)
        at org.jivesoftware.smack.AsyncButOrdered$Handler.run(AsyncButOrdered.java:151)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: java.lang.NoSuchFieldException: ELEMENT
        at java.lang.Class.getField(Class.java:1604)
        at org.jivesoftware.smack.util.XmppElementUtil.getQNameFor(XmppElementUtil.java:48)
        at org.jivesoftware.smack.packet.StanzaView.getExtension(StanzaView.java:91) 
        at net.java.sip.communicator.impl.protocol.jabber.ChatRoomJabberImpl$ParticipantListener.processOtherPresence(ChatRoomJabberImpl.java:2827) 
        at net.java.sip.communicator.impl.protocol.jabber.ChatRoomJabberImpl$ParticipantListener.processPresence(ChatRoomJabberImpl.java:2721) 
        at org.jivesoftware.smackx.muc.MultiUserChat$3.processStanza(MultiUserChat.java:266) 
        at org.jivesoftware.smack.AbstractXMPPConnection.lambda$invokeStanzaCollectorsAndNotifyRecvListeners$6(AbstractXMPPConnection.java:1591) 
        at org.jivesoftware.smack.-$$Lambda$AbstractXMPPConnection$WvFNBjGAjT0-wl3E33Swy31nrjY.run(Unknown Source:4) 
        at org.jivesoftware.smack.AsyncButOrdered$Handler.run(AsyncButOrdered.java:151) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919)

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.