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.
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'
},