Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Exception: java.lang.IllegalArgumentException: The generic type <V extends MvpView> must be the first generic type argument of class #344

Open
ptsiogas opened this issue Apr 22, 2021 · 3 comments

Comments

@ptsiogas
Copy link

Mosby Version:
3.1.1

Expected behavior
Not to crash.

Actual behavior (include a stacktrace if crash)

Fatal Exception: java.lang.IllegalArgumentException: The generic type <V extends MvpView> must be the first generic type argument of class PostRegisterPresenter (per convention). Otherwise we can't determine which type of View this Presenter coordinates.
       at com.hannesdorfmann.mosby3.mvp.MvpNullObjectBasePresenter.<init>(MvpNullObjectBasePresenter.java:73)
       at mypackage.com.sdk.ui.base.BasePresenter.<init>(BasePresenter.java:15)
       at mypackage.com.sdk.ui.flow.register.PostRegisterPresenter.<init>(PostRegisterPresenter.java:16)
       at mypackage.com.sdk.core.di.module.PresenterModule.providePostRegisterPresenter(PresenterModule.java:227)
       at mypackage.com.sdk.core.di.module.PresenterModule_ProvidePostRegisterPresenterFactory.providePostRegisterPresenter(PresenterModule_ProvidePostRegisterPresenterFactory.java:29)
       at mypackage.com.sdk.core.di.component.DaggerLiveDIComponent.injectPostRegisterFragment(DaggerLiveDIComponent.java:786)
       at mypackage.com.sdk.core.di.component.DaggerLiveDIComponent.inject(DaggerLiveDIComponent.java:516)
       at mypackage.com.sdk.ui.flow.register.PostRegisterFragment.injectFragment(PostRegisterFragment.java:76)
       at mypackage.com.sdk.ui.base.BaseFragment.onAttach(BaseFragment.java:115)
       at androidx.fragment.app.Fragment.onAttach(Fragment.java:1603)
       at androidx.fragment.app.Fragment.performAttach(Fragment.java:2673)
       at androidx.fragment.app.FragmentStateManager.attach(FragmentStateManager.java:263)
       at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1182)
       at androidx.fragment.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1255)
       at androidx.fragment.app.FragmentTransition.calculateFragments(FragmentTransition.java:1138)
       at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:136)
       at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2001)
       at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1959)
       at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1861)
       at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7094)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)

Caused by java.lang.ClassCastException: libcore.reflect.TypeVariableImpl cannot be cast to java.lang.Class
       at com.hannesdorfmann.mosby3.mvp.MvpNullObjectBasePresenter.<init>(MvpNullObjectBasePresenter.java:58)
       at mypackage.com.ui.base.BasePresenter.<init>(BasePresenter.java:15)
       at mypackage.com.ui.flow.register.PostRegisterPresenter.<init>(PostRegisterPresenter.java:16)
       at mypackage.com.core.di.module.PresenterModule.providePostRegisterPresenter(PresenterModule.java:227)
       at mypackage.com.core.di.module.PresenterModule_ProvidePostRegisterPresenterFactory.providePostRegisterPresenter(PresenterModule_ProvidePostRegisterPresenterFactory.java:29)
       at mypackage.com.core.di.component.DaggerLiveDIComponent.injectPostRegisterFragment(DaggerLiveDIComponent.java:786)
       at mypackage.com.core.di.component.DaggerLiveDIComponent.inject(DaggerLiveDIComponent.java:516)
       at mypackage.com.ui.flow.register.PostRegisterFragment.injectFragment(PostRegisterFragment.java:76)
       at mypackage.com.ui.base.BaseFragment.onAttach(BaseFragment.java:115)
       at androidx.fragment.app.Fragment.onAttach(Fragment.java:1603)
       at androidx.fragment.app.Fragment.performAttach(Fragment.java:2673)
       at androidx.fragment.app.FragmentStateManager.attach(FragmentStateManager.java:263)
       at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1182)
       at androidx.fragment.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1255)
       at androidx.fragment.app.FragmentTransition.calculateFragments(FragmentTransition.java:1138)
       at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:136)
       at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2001)
       at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1959)
       at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1861)
       at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7094)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)

Our classes:

@EFragment
public class PostRegisterFragment extends BaseFragment<PostRegisterView, PostRegisterPresenter> implements PostRegisterView
public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V>> extends MvpFragment<V, P> implements BaseView
public interface PostRegisterView extends BaseView
public interface BaseView extends MvpView
public class PostRegisterPresenter extends BasePresenter<PostRegisterView>
public abstract class BasePresenter<V extends BaseView> extends MvpNullObjectBasePresenter<V>

Steps to reproduce the behavior or link to a sample repository

  • We received the logs from Google Play Store crashlytics. Until now we do not have any replication steps.
  • It seems that it doesn't affect all of our users.
  • Also we have proguard enabled.
  • The issue appeared out of the blue, we did not made any changes at those classes in our latest release.
  • We used to have mosby 2.0.1 when we first got the issue yesterday, we updated to 3.1.1 in order to fix the problem.
  • The problem seems to be contained a little but it still persists.
@ptsiogas
Copy link
Author

ptsiogas commented Jun 8, 2021

Guys do you have any news about that? Is this project still active?

@luiscurini
Copy link

Hi!

I'm not quite sure why this is happening. I'm encountering the same issue but only with AS gradle plugin 4.2+ and gradle 6.7+. I reverted my configuration to use temporarily gradle plugin 4.1.3 and gradle 6.5.

This seems to me like an R8 / proguard rule that it's missing. Debug builds, which are not obfuscated, work without any issues.

@Stonos
Copy link

Stonos commented Aug 26, 2021

Try adding the following keep rules if you're using R8 with Full Mode enabled:

-keep,allowobfuscation,allowshrinking class com.hannesdorfmann.mosby3.mvp.MvpNullObjectBasePresenter { *; }
-keep,allowobfuscation,allowshrinking class * extends com.hannesdorfmann.mosby3.mvp.MvpNullObjectBasePresenter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants