powered by Jive Software

Smack 4.4.0: All aTalk implementation of Extension Element Provider classes are being rejected by AbstractProvider

aTalk implements a DefaultExtensionElementProvider class using the following:

public class DefaultExtensionElementProvider<EE extends AbstractExtensionElement> extends ExtensionElementProvider

Most of the aTalk XMPP extensions are then derived from the DefaultExtensionElementProvider class.

However when trying to register such aTalk provider class with smack e.g.

  /* Tell Smack what are the additional IQProviders that aTalk can support */
  // register our coin provider
  ProviderManager.addIQProvider(CoinIQ.ELEMENT, CoinIQ.NAMESPACE, new CoinIQProvider());

smack always throws ClassCastException (see debug log);

ClassCastException: libcore.reflect.TypeVariableImpl cannot be cast to java.lang.Class

2020-08-07 12:55:03.974 1847-2151/org.atalk.android E/(AccountManager.java:401)#runInLoadStoredAccountsThread: Failed to load accounts for net.java.sip.communicator.impl.protocol.jabber.ProtocolProviderFactoryJabberImpl@17b7c28
    java.lang.ClassCastException: libcore.reflect.TypeVariableImpl cannot be cast to java.lang.Class
        at org.jivesoftware.smack.provider.AbstractProvider.<init>(AbstractProvider.java:39)
        at org.jivesoftware.smack.provider.Provider.<init>(Provider.java:40)
        at org.jivesoftware.smack.provider.ExtensionElementProvider.<init>(ExtensionElementProvider.java:29)
        at org.xmpp.extensions.DefaultExtensionElementProvider.<init>(DefaultExtensionElementProvider.java:43)
        at org.xmpp.extensions.coin.CoinIQProvider.<init>(CoinIQProvider.java:46)
        at net.java.sip.communicator.impl.protocol.jabber.ProtocolProviderServiceJabberImpl.initialize(ProtocolProviderServiceJabberImpl.java:2088)
        at net.java.sip.communicator.impl.protocol.jabber.ProtocolProviderFactoryJabberImpl.createService(ProtocolProviderFactoryJabberImpl.java:121)
        at net.java.sip.communicator.service.protocol.ProtocolProviderFactory.loadAccount(ProtocolProviderFactory.java:934)
        at net.java.sip.communicator.service.protocol.AccountManager.doLoadStoredAccounts(AccountManager.java:139)
        at net.java.sip.communicator.service.protocol.AccountManager.loadStoredAccounts(AccountManager.java:294)
        at net.java.sip.communicator.service.protocol.AccountManager.runInLoadStoredAccountsThread(AccountManager.java:394)
        at net.java.sip.communicator.service.protocol.AccountManager.access$000(AccountManager.java:36)
        at net.java.sip.communicator.service.protocol.AccountManager$1.run(AccountManager.java:329)

To resolve the above problem, aTalk needs to apply the attached patch, then everything is working properly. Similar patch is already required for earlier version of smack releases e.g. 4.3.x.

AbstractProvider.patch (959 Bytes)

Appreciate if smack team can advice what are changes required in aTalk implementation to avoid ClassCastException being thrown by smack. Really needs some advice as I am a bit lost in these areas.

Alternately, would smack team consider applying the proposed patch to smack AbstractProvider classs.

=========== Further info for the request ==========
In order to make the patched file coexists with smack-core library, it has to use the jarjar tool as shown below, and other modifications in ./aTalk/build.gradle file. It seems Android Studio (AS) at times is having problem dealing with aTalk jarjar implementation, and giving unexplained problems all these while. By omitting the below jarjar command/patch for smack-core, the reported problem (last) can be resolved; note: last founding is not reflected in the link below.

android studio regularly but randomly throws error a jar file is missing in the map and stop during the build process

    jarjar.repackage {
        from("org.igniterealtime.smack:smack-core:$smackVersion") {
            transitive = false
        }
        destinationDir new File("${projectDir}/../aTalk/third_party/m2/org/igniterealtime/smack/smack-core-jarjar/${smackVersion}")
        destinationName "smack-core-jarjar-${smackVersion}.jar"

        // smack-core
        classDelete 'org.jivesoftware.smack.provider.AbstractProvider'
    },

Please consider also showing small patches inline, that makes them easier accessible and discussable.

Here is the patch you are suggesting:

--- /home/cmeng/source/smack/Smack-4.4.0-alpha3-20200404/org/jivesoftware/smack/provider/AbstractProvider.java  2020-03-24 09:16:10.000000000 
+++ /home/cmeng/workspace/android/atalk-android/aTalk/src/main/java/org/jivesoftware/smack/provider/AbstractProvider.java   2020-04-06 12:16:22.000000000 
@@ -33,13 +33,17 @@
             currentType = currentClass.getGenericSuperclass();
         }
         ParameterizedType parameterizedGenericSuperclass = (ParameterizedType) currentType;
         Type[] actualTypeArguments = parameterizedGenericSuperclass.getActualTypeArguments();
         Type elementType = actualTypeArguments[0];
 
+        // required by aTalk class otherwise elementType is only resolved to <EE>
+        if (!(elementType instanceof Class))
+            elementType = elementType.getClass();
+
         elementClass =  (Class<E>) elementType;
     }
 
     public final Class<E> getElementClass() {
         return elementClass;
     }
 }

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