android10 / frodo

Android Library for Logging RxJava Observables and Subscribers.
1.48k stars 101 forks source link

Frodo + Robolectric NullPointerException #22

Closed cesards closed 8 years ago

cesards commented 8 years ago

Whenever I run my tests, the ones who use Frodo annotated methods get a NullPointerException. It looks like they don't get well with Robolectric. Do they?

java.lang.NullPointerException
    at com.fernandocejas.frodo.aspect.LogObservable.methodAnnotatedWithRxLogObservable(LogObservable.java:27)
    at xxx.widget.ExpandingAutoFitRecyclerView.getExpansionObservable(ExpandingAutoFitRecyclerView.java)
    at xxx.shows.series.SeriesListViewImpl.onListExpansionChanged(SeriesListViewImpl.java:174)
    at xxx.shows.ShowActivity.setupSubscriptions(ShowActivity.java:175)
    at xxx.shows.ShowActivity.onResume(ShowActivity.java:128)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185)
    at android.app.Activity.performResume(Activity.java:5182)
    at org.robolectric.util.ReflectionHelpers$3.run(ReflectionHelpers.java:162)
    at org.robolectric.util.ReflectionHelpers.traverseClassHierarchy(ReflectionHelpers.java:305)
    at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:156)
    at org.robolectric.util.ComponentController$1.run(ComponentController.java:72)
    at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:304)
    at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:45)
    at org.robolectric.util.ComponentController.invokeWhilePaused(ComponentController.java:69)
    at org.robolectric.util.ActivityController.resume(ActivityController.java:153)
    at xxx.shows.ShowActivityTest.setUp(ShowActivityTest.java:64)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:251)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:27)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

The failing method is:

@Pointcut("execution(@com.fernandocejas.frodo.annotation.RxLogObservable * *(..)) && if()")
public static boolean methodAnnotatedWithRxLogObservable(ProceedingJoinPoint joinPoint) {
    FrodoProceedingJoinPoint frodoJoinPoint = new FrodoProceedingJoinPoint(joinPoint);
    Annotation annotation = frodoJoinPoint.getAnnotation(RxLogObservable.class);
    return ((MethodSignature)joinPoint.getSignature()).getReturnType() == Observable.class && ((RxLogObservable)annotation).value() != Scope.NOTHING;
}

Do you need more info?

cesards commented 8 years ago

Actually is crashing as well in production:

03-14 12:14:04.162 18903-18903/xxx E/AndroidRuntime: FATAL EXCEPTION: main
                                                                   java.lang.RuntimeException: Unable to resume activity {xxx/xxx.home.HomeActivity}: java.lang.NullPointerException
                                                                       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2595)
                                                                       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2623)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2100)
                                                                       at android.app.ActivityThread.access$600(ActivityThread.java:137)
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                       at android.os.Looper.loop(Looper.java:213)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:4791)
                                                                       at java.lang.reflect.Method.invokeNative(Native Method)
                                                                       at java.lang.reflect.Method.invoke(Method.java:511)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
                                                                       at dalvik.system.NativeStart.main(Native Method)
                                                                    Caused by: java.lang.NullPointerException
                                                                       at com.fernandocejas.frodo.aspect.LogObservable.methodAnnotatedWithRxLogObservable(LogObservable.java:27)
                                                                       at xxx.home.HomeActivity.onChannelPageChanged(HomeActivity.java)
                                                                       at xxx.home.HomePresenter.setupSubscriptions(HomePresenter.java:103)
                                                                       at xxx.home.HomePresenter.onViewWillShow(HomePresenter.java:76)
                                                                       at xxx.home.HomeActivity.onResume(HomeActivity.java:197)
                                                                       at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)
                                                                       at android.app.Activity.performResume(Activity.java:5082)
                                                                       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2585)
                                                                       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2623) 
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2100) 
                                                                       at android.app.ActivityThread.access$600(ActivityThread.java:137) 
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206) 
                                                                       at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                       at android.os.Looper.loop(Looper.java:213) 
                                                                       at android.app.ActivityThread.main(ActivityThread.java:4791) 
                                                                       at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                       at java.lang.reflect.Method.invoke(Method.java:511) 
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 
                                                                       at dalvik.system.NativeStart.main(Native Method) 
android10 commented 8 years ago

It is not this project responsibility to support 3rd party libraries like robolectric and if you have issues with it, please send a PR.

On the other hand, if it is crashing on your android app, can you post sample code so this can be reproduced and for instance evaluate whether is an issue and give it a priority?

Thanks!