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

Fix NPE if dismiss() is called before show() #87

Merged
merged 2 commits into from
Nov 5, 2017
Merged

Fix NPE if dismiss() is called before show() #87

merged 2 commits into from
Nov 5, 2017

Conversation

SUPERCILEX
Copy link
Contributor

Upgrading to v2.2+ gives me this crash:

11-03 20:50:19.714 19598-19598/com.supercilex.robotscouter.debug E/UncaughtException: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.LocaleList android.text.TextPaint.getTextLocales()' on a null object reference
                                                                                          at android.text.StaticLayout.generate(StaticLayout.java:608)
                                                                                          at android.text.StaticLayout.<init>(StaticLayout.java:588)
                                                                                          at android.text.StaticLayout.<init>(Unknown Source:0)
                                                                                          at android.text.StaticLayout$Builder.build(StaticLayout.java:399)
                                                                                          at uk.co.samuelwall.materialtaptargetprompt.extras.PromptUtils.createStaticTextLayout(PromptUtils.java:240)
                                                                                          at uk.co.samuelwall.materialtaptargetprompt.extras.PromptText.createTextLayout(PromptText.java:237)
                                                                                          at uk.co.samuelwall.materialtaptargetprompt.extras.PromptText.update(PromptText.java:263)
                                                                                          at uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.updateAnimation(MaterialTapTargetPrompt.java:473)
                                                                                          at uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt$5.onAnimationUpdate(MaterialTapTargetPrompt.java:311)
                                                                                          at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1522)
                                                                                          at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:654)
                                                                                          at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:617)
                                                                                          at android.animation.ValueAnimator.start(ValueAnimator.java:1046)
                                                                                          at android.animation.ValueAnimator.start(ValueAnimator.java:1065)
                                                                                          at uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.dismiss(MaterialTapTargetPrompt.java:328)
                                                                                          at com.supercilex.robotscouter.util.ui.TutorialUtilsKt$showAddTeamTutorial$1.onChanged(TutorialUtils.kt:42)
                                                                                          at com.supercilex.robotscouter.util.ui.TutorialUtilsKt$showAddTeamTutorial$1.onChanged(TutorialUtils.kt:21)
                                                                                          at android.arch.lifecycle.LiveData.considerNotify(LiveData.java:131)
                                                                                          at android.arch.lifecycle.LiveData.dispatchingValue(LiveData.java:148)
                                                                                          at android.arch.lifecycle.LiveData.setValue(LiveData.java:294)
                                                                                          at android.arch.lifecycle.MutableLiveData.setValue(MutableLiveData.java:33)
                                                                                          at com.supercilex.robotscouter.util.data.UniqueMutableLiveData.setValue(DatabaseUtils.kt:167)
                                                                                          at com.supercilex.robotscouter.ui.teamlist.TutorialHelper.onDataChanged(TutorialHelper.kt:45)
                                                                                          at com.firebase.ui.common.BaseObservableSnapshotArray.notifyOnDataChanged(BaseObservableSnapshotArray.java:163)
                                                                                          at com.firebase.ui.firestore.FirestoreArray.onEvent(FirestoreArray.java:92)
                                                                                          at com.firebase.ui.firestore.FirestoreArray.onEvent(FirestoreArray.java:21)
                                                                                          at com.google.firebase.firestore.zzi.onEvent(Unknown Source:16)
                                                                                          at com.google.android.gms.internal.zzejz.zza(Unknown Source:6)
                                                                                          at com.google.android.gms.internal.zzeka.run(Unknown Source:6)
                                                                                          at android.os.Handler.handleCallback(Handler.java:790)
                                                                                          at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                          at android.os.Looper.loop(Looper.java:164)
                                                                                          at android.app.ActivityThread.main(ActivityThread.java:6494)
                                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                                          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

I have a database listener which only knows if a user has tapped a prompt or not. I use an observable model that shows or dismisses the prompt based on that boolean flag. Thus, I have no knowledge of the current state of the prompt, just the state it should be in. This means I'll be possibly calling dismiss() before show() which causes the above NPE.

To fix this problem, we now save our current state instead of the limited mDismissing field. In addition, I've added a getState() method though that isn't necessary to fix the bug.

@codecov-io
Copy link

codecov-io commented Nov 4, 2017

Codecov Report

Merging #87 into master will decrease coverage by 0.36%.
The diff coverage is 23.07%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #87      +/-   ##
============================================
- Coverage     93.82%   93.46%   -0.37%     
- Complexity      300      308       +8     
============================================
  Files            14       14              
  Lines          1020     1025       +5     
  Branches        117      117              
============================================
+ Hits            957      958       +1     
- Misses           39       40       +1     
- Partials         24       27       +3
Impacted Files Coverage Δ Complexity Δ
...terialtaptargetprompt/MaterialTapTargetPrompt.java 83.83% <23.07%> (-1.1%) 29 <12> (+8)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e695f08...d06c450. Read the comment docs.

@sjwall sjwall merged commit 502593e into sjwall:master Nov 5, 2017
@sjwall
Copy link
Owner

sjwall commented Nov 5, 2017

Thanks for your pull request the changes have been released in v2.4.0

@SUPERCILEX SUPERCILEX deleted the npe branch November 5, 2017 18:01
@SUPERCILEX
Copy link
Contributor Author

Awesome!

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

Successfully merging this pull request may close these issues.

3 participants