android10 / frodo

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

NPE in annotated method: Observable<Void> #11

Closed Android-s14 closed 8 years ago

Android-s14 commented 8 years ago

Caught this exception:

E/AndroidRuntime( 9441): java.lang.NullPointerException
E/AndroidRuntime( 9441):    at com.fernandocejas.frodo.aspect.LogObservable.methodAnnotatedWithRxLogObservable(LogObservable.java:27)

Happened for a method with the following signature:

@RxLogObservable
private Observable<Void> method(View view);
android10 commented 8 years ago

@Android-s14 interesting. Thanks for reporting. Will try to reproduce and mark it as bug.

dbacinski commented 8 years ago

The same problem occurs for methods run from junit test.

        Annotation annotation = frodoJoinPoint.getAnnotation(RxLogObservable.class);

annotation is always null

android10 commented 8 years ago

@dbacinski thanks. I marked this as a bug. It is gonna be fixed within the next release very soon :)

dbacinski commented 8 years ago

I have reproduced it in the sample app, here is a failing test: https://github.com/dbacinski/frodo/commit/75c2b1b59668badc6441c26e3f898d9210666c0f

dbacinski commented 8 years ago

Changing annotations retention to RUNTIME fixes NPE: https://github.com/dbacinski/frodo/commit/fb6eed2900c7e6d0c0c944c2f5231267be01c976

dbacinski commented 8 years ago

https://github.com/android10/frodo/pull/12

android10 commented 8 years ago

@dbacinski awesome! Will look into the PR asap.

Philio commented 8 years ago

Had a similar crash, possibly the same issue:

Caused by: java.lang.NullPointerException
    at com.fernandocejas.frodo.aspect.LogObservable.methodAnnotatedWithRxLogObservable(LogObservable.java:27)

Code:

@RxLogObservable
public Observable<Pair<UserTotal, List<ActiveCompetition>>> loadActiveCompetitions() {

Works on Android 6, crash was on 4.4.4

dbacinski commented 8 years ago

@android10 any update?

ayanyev commented 8 years ago

Hi, when I rolled back to 0.8.1, got rid of Scopes and I stop getting such an error

dbacinski commented 8 years ago

@ayanyev good point, problem is due to accesing Scope stored in Annotation in runtime.

android10 commented 8 years ago

Sorry guys. I have been out for a while. @dbacinski will review your PR by the end of the week.

dbacinski commented 8 years ago

will be fixed in next version - 0.8.3

Android-s14 commented 8 years ago

@android10 any plans to release a new version with the fix? Thank you.

android10 commented 8 years ago

@Android-s14 yes! by the end of next week there is gonna be a release :). I have to add some tests and another fix and I'm done.

Rainer-Lang commented 8 years ago

@android10 Don't want to rush you... Same problem here...

android10 commented 8 years ago

There is an open PR for this, feel free to review as well: https://github.com/android10/frodo/pull/18

android10 commented 8 years ago

@dbacinski @Rainer-Lang @Android-s14 still cannot reproduce this problem. I added more samples to reproduce the problem and by both Observable.just(null) and Observable<Void> and everything seems to be fine:

D  Frodo => [@Observable#doNothing -> onSubscribe()]
D  Frodo => [@Observable#doNothing -> onCompleted()]
D  Frodo => [@Observable#doNothing -> onTerminate()]
D  Frodo => [@Observable#doNothing -> @Emitted -> 0 elements :: @Time -> 0 ms]
D  Frodo => [@Observable#doNothing ->  :: @ObserveOn -> main]
D  Frodo => [@Observable#doNothing -> onUnsubscribe()]                        

D  Frodo => [@Observable#doSomething -> onSubscribe()]
D  Frodo => [@Observable#doSomething -> onNext() -> null]
D  Frodo => [@Observable#doSomething -> onCompleted()]
D  Frodo => [@Observable#doSomething -> onTerminate()]
D  Frodo => [@Observable#doSomething -> @Emitted -> 1 element :: @Time -> 0 ms]
D  Frodo => [@Observable#doSomething -> @SubscribeOn -> RxNewThreadScheduler-5 :: @ObserveOn -> main]
D  Frodo => [@Observable#doSomething -> onUnsubscribe()]                        

D  Frodo => [@Observable#sendNull -> onSubscribe()]
D  Frodo => [@Observable#sendNull -> onNext() -> null]
D  Frodo => [@Observable#sendNull -> onCompleted()]
D  Frodo => [@Observable#sendNull -> onTerminate()]
D  Frodo => [@Observable#sendNull -> @Emitted -> 1 element :: @Time -> 0 ms]
D  Frodo => [@Observable#sendNull -> @SubscribeOn -> RxNewThreadScheduler-6 :: @ObserveOn -> main]
D  Frodo => [@Observable#sendNull -> onUnsubscribe()]

Here is the commit: https://github.com/android10/frodo/commit/e281739cea7577d8143858b371627252535f4808

dbacinski commented 8 years ago

@android10 did you try to run this test: https://github.com/dbacinski/frodo/commit/75c2b1b59668badc6441c26e3f898d9210666c0f

android10 commented 8 years ago

@dbacinski this is the failing line?

numbers.toList().toBlocking().single()

Can you provide the stack trace? I'm afraid this could be a robolectric issue...Not sure.

android10 commented 8 years ago

By the way what you are mentioning, works to me. Actually I added an example: https://github.com/android10/frodo/commit/8b6e094387ff4b287bad22c26deeb66a7b211c9b

Here is the output:

D  Frodo => [@Observable :: @InClass -> ObservableSample :: @Method -> moreNumbers()]
D  Frodo => [@Observable#moreNumbers -> onSubscribe()]
D  Frodo => [@Observable#moreNumbers -> onNext() -> 1]
D  Frodo => [@Observable#moreNumbers -> onNext() -> 2]
D  Frodo => [@Observable#moreNumbers -> onNext() -> 3]
D  Frodo => [@Observable#moreNumbers -> onNext() -> 4]
D  Frodo => [@Observable#moreNumbers -> onCompleted()]
D  Frodo => [@Observable#moreNumbers -> onTerminate()]
D  Frodo => [@Observable#moreNumbers -> @Emitted -> 4 elements :: @Time -> 0 ms]
D  Frodo => [@Observable#moreNumbers -> @SubscribeOn -> main :: @ObserveOn -> main]
D  Frodo => [@Observable#moreNumbers -> onUnsubscribe()]