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

IllegalArgumentException: class java.lang.Object is not an interface #159

Closed
Maragues opened this issue Sep 6, 2016 · 16 comments
Closed
Milestone

Comments

@Maragues
Copy link

Maragues commented Sep 6, 2016

This stacktrace is shown when attempting to detach an Activity that uses MvpNullObjectBasePresenter but does not implement any Interface

java.lang.RuntimeException: Unable to destroy activity {com.mypackage/com.mypackage.ui.account.AccountActivity}: java.lang.IllegalArgumentException: class java.lang.Object is not an interface
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3831)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3849)
        at android.app.ActivityThread.-wrap5(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5422)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
        Caused by: java.lang.IllegalArgumentException: class java.lang.Object is not an interface
at java.lang.reflect.Proxy.getProxyClass(Proxy.java:147)
        at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:228)
        at com.hannesdorfmann.mosby.mvp.NoOp.of(NoOp.java:41)
        at com.hannesdorfmann.mosby.mvp.MvpNullObjectBasePresenter.detachView(MvpNullObjectBasePresenter.java:42)
        at com.hannesdorfmann.mosby.mvp.delegate.MvpInternalDelegate.detachView(MvpInternalDelegate.java:70)
        at com.hannesdorfmann.mosby.mvp.delegate.ActivityMvpDelegateImpl.onDestroy(ActivityMvpDelegateImpl.java:71)
        at com.hannesdorfmann.mosby.mvp.MvpActivity.onDestroy(MvpActivity.java:47)
        at android.app.Activity.performDestroy(Activity.java:6422)
        at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1142)
        at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3818)
        at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3849) 
        at android.app.ActivityThread.-wrap5(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5422) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

I feel that the error message could be improved by checking in MvpNullObjectBasePresenter if the class to be detached implements MvpView, but I'm not sure if that's the best way, I haven't dig too much into Mosby code

Class<V> viewClass = (Class<V>) types[0];
//add check here? Throw an Exception if it doesn't implement MvpView?
view = NoOp.of(viewClass);

Also, this error is only happening in release version with ProGuard. It's been in development like that for months and it hasn't crashed.

@sockeqwe
Copy link
Owner

sockeqwe commented Sep 6, 2016

Thanks for reporting.
Which version of Mosby do you use? I assume 2.x , because I think this issue has been solved with Mosby 3.0.0-SNAPSHOT

@Maragues
Copy link
Author

Maragues commented Sep 6, 2016

Sorry I forgot to mention, it's version 2.0.1

@sockeqwe
Copy link
Owner

sockeqwe commented Sep 6, 2016

Could you please try it with latest 3.0.0-SNAPSHOT and let me know whether or not this issue still occurs in 3.0.0-SNAPSHOT

@Maragues
Copy link
Author

Maragues commented Sep 6, 2016

My code does not compile with 3.0.0-SNAPSHOT, it looks like BaseMvpViewStateDelegateCallback no longer exists

@sockeqwe
Copy link
Owner

sockeqwe commented Sep 6, 2016

I think it has been renamed to MvpViewStateDelegateCallback

@Maragues
Copy link
Author

Maragues commented Sep 6, 2016

It doesn't crash in 3.0.0-SNAPSHOT, I see that you catch the exception in MvpNullObjectBasePresenter's constructor

@sockeqwe
Copy link
Owner

sockeqwe commented Sep 6, 2016

Thanks for your feedback. So it's not crashing, but it should crash since the view is not implementing the view interface, right? or does base class you extend from implement MvpView interface?

@Maragues
Copy link
Author

Maragues commented Sep 6, 2016

It's not crashing, but com.hannesdorfmann.mosby.mvp.MvpActivity does implement MvpView

@sockeqwe
Copy link
Owner

sockeqwe commented Sep 6, 2016

Ok, I have to dive into the code again to verify whether or not this is the desired behavior.

Just to sum it up:

You have a FooActivity extend MvpActivity<FooPresenter, FooView> (but FooActivity doesn't implement FooView) and a FooPresenter extends MvpNullObjectBasePresenter<FooView>. Is that correct?

@Maragues
Copy link
Author

Maragues commented Sep 6, 2016

Yes, that's the scenario. Some details

  • The Activity is empty, it's just a Fragment container
  • It didn't crash in version 2.0.1 until I used ProGuard

@sockeqwe
Copy link
Owner

sockeqwe commented Sep 6, 2016

Got it! I have to verify the source code ... Regarding proguard, I guess a
rule is missing here, will check that too ... Thanks for your patience!

Miguel Aragues notifications@github.com schrieb am Di., 6. Sep. 2016 um
18:01 Uhr:

Yes, that's the scenario. Some details

  • The Activity is empty, it's just a Fragment container
  • It didn't crash in version 2.0.1 until I used ProGuard


You are receiving this because you commented.

Reply to this email directly, view it on GitHub
#159 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAjnrsSuUtKn0dsdI_QJT3UJZ4CCcIJ6ks5qnY50gaJpZM4J146O
.

@Maragues
Copy link
Author

Maragues commented Sep 6, 2016

Thanks to you for the time you devote to the community!

@sockeqwe sockeqwe added this to the 3.0 milestone Sep 15, 2016
@mohaxspb
Copy link

mohaxspb commented Jan 4, 2017

I have same error when tryed to add parametr to my extention of MvpView interface. I tryed to compile with 3.0.0-SNAPSHOT, but gradle cant find it

@sockeqwe
Copy link
Owner

sockeqwe commented Jan 4, 2017 via email

@mohaxspb
Copy link

mohaxspb commented Jan 5, 2017

My base interface looks like

public interface BaseListMvp {
    interface View<D> extends BaseMvpView {
        void updateData(List<D> data);
    }

    interface Presenter<D, V extends View> extends BaseDataPresenter<V> {
        List<D> getData();
    }
}

I also create BaseListPresenter

public abstract class BaseListArticlesPresenter<D extends RealmObject, V extends BaseListMvp.View<D>>
        extends BasePresenter<V> implements BaseListMvp.Presenter<D, V> {

    protected RealmResults<D> mData;

    public BaseListArticlesPresenter(MyPreferenceManager myPreferencesManager, DbProviderFactory dbProviderFactory, ApiClient apiClient) {
        super(myPreferencesManager, dbProviderFactory, apiClient);
    }

    @Override
    public List<D> getData() {
        return mData;
    }
}

And finaly create concrete presenter so:

public class RecentArticlesPresenter extends BaseListArticlesPresenter<Article, RecentArticles.View> implements RecentArticles.Presenter {

    public RecentArticlesPresenter(MyPreferenceManager myPreferencesManager, DbProviderFactory dbProviderFactory, ApiClient apiClient) {
        super(myPreferencesManager, dbProviderFactory, apiClient);
    }
}

where RecentArticles interface is

public interface RecentArticles {
    interface View extends BaseListMvp.View<Article> {
    }

    interface Presenter extends BaseListMvp.Presenter<Article, View> {
    }
}

And it works until I try to replace fragement or rotate screen, after fragment try to destoy them self. Then onDestroy called and an error. that mentioned previously in this issue occures

sockeqwe added a commit that referenced this issue Jan 9, 2017
@sockeqwe
Copy link
Owner

sockeqwe commented Jan 9, 2017

@mohaxspb I tried to reproduce your issue, but I can't reproduce it. I have added a unit test with your interface specifications, but it is not crashing.

Could you please take a look here and verify that the classes / interface are equal to what you have:
https://github.com/sockeqwe/mosby/tree/master/mvp-common/src/test/java/com/hannesdorfmann/mosby3/mvp/test/regression159

and the corresponding test:
https://github.com/sockeqwe/mosby/blob/master/mvp-common/src/test/java/com/hannesdorfmann/mosby3/mvp/test/regression159/MvpNullObjectBasePresenterRegression159Test.java

Could you also post your stacktrace here?
Are you absolutely sure that you are using 3.0.0-SNAPSHOT? because the exception should be called directly in constructor (if null object releated) and not when view is detached / because fragment has been destroyed.

@sockeqwe sockeqwe closed this as completed Mar 9, 2017
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