powered by Jive Software

Smack 4.4.0 aTalk implemented IQProvider always failed when calling ProviderProviderManager.addIQProvider()

aTalk implemented IQProvider classes always failed with below exception when making call to ProviderProviderManager.addIQProvider(). Most aTalk IQProviders extension elements providers are implemented as shown below.

/**
 * Provider for URIs packet extension.
 */
private final DefaultExtensionElementProvider<URIsExtensionElement> urisProvider
        = new DefaultExtensionElementProvider<>(URIsExtensionElement.class);

public class DefaultExtensionElementProvider<EE extends AbstractExtensionElement> extends ExtensionElementProvider<EE>

For aTalk class to work properly, it needs the following changes to the Provider constructor.
Any clues why aTalk class failed smack type check?
Any recommendation to make aTalk classes work with smack without the following changes.

    protected Provider() {
        Type currentType = getClass().getGenericSuperclass();
        while (!(currentType instanceof ParameterizedType)) {
            Class<?> currentClass = (Class<?>) currentType;
            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;
    }
========== aTalk IQProvider exception ================
2019-10-11 08:24:18.667 32191-32457/org.atalk.android E/(AccountManager.java:401)#runInLoadStoredAccountsThread: Failed to load accounts for net.java.sip.communicator.impl.protocol.jabber.ProtocolProviderFactoryJabberImpl@b1b5096
    java.lang.ClassCastException: libcore.reflect.TypeVariableImpl cannot be cast to java.lang.Class
        at org.jivesoftware.smack.provider.Provider.<init>(Provider.java:61)
        at org.jivesoftware.smack.provider.ExtensionElementProvider.<init>(ExtensionElementProvider.java:29)
        at org.xmpp.extensions.DefaultExtensionElementProvider.<init>(DefaultExtensionElementProvider.java:46)
        at org.xmpp.extensions.coin.CoinIQProvider.<init>(CoinIQProvider.java:46)
        at net.java.sip.communicator.impl.protocol.jabber.ProtocolProviderServiceJabberImpl.initialize(ProtocolProviderServiceJabberImpl.java:2024)
        at net.java.sip.communicator.impl.protocol.jabber.ProtocolProviderFactoryJabberImpl.createService(ProtocolProviderFactoryJabberImpl.java:121)
        at net.java.sip.communicator.service.protocol.ProtocolProviderFactory.loadAccount(ProtocolProviderFactory.java:918)
        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)