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

refactor: improve logs related to deckPicker in StudyOptionsFragment #17291

Merged
merged 2 commits into from
Oct 24, 2024

Conversation

criticalAY
Copy link
Contributor

Purpose / Description

Improvise the logs in StudyOptionsFragment to find the exact cause of NPE in study option fragment

Fixes

How Has This Been Tested?

Local build

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One blocker on the comment, rest are preferences

@david-allison david-allison added Needs Author Reply Waiting for a reply from the original author Needs Second Approval Has one approval, one more approval to merge labels Oct 20, 2024
@mikehardy mikehardy changed the title refactor: improvise logs related to deckPicker in StudyOptionsFragment refactor: improve logs related to deckPicker in StudyOptionsFragment Oct 20, 2024
Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will convert a crash that is the reason we saw this problem into a bunch of log warnings that we will never see

@mikehardy
Copy link
Member

I think we should send an error report at least

I think it should still be non-null, but, the getter is just returning activity, perhaps it should return requireActivity then it will still crash, but it will have an obvious error

All of the activity results should have an isAdded check from Fragment, no need to do the work if the fragment has been detached and disposed?

and configureToolbar shouldn't be run in onCreateView, it should probably run onAttach ?

In those cases I don't think it's ever possible for Activity to be null (onAttach it will exist, and if !Added and you avoid, then you will avoid when it is not null)

And if we somehow still attempt to fetch the deckPicker / activity then it will still crash so we'll see it

@criticalAY
Copy link
Contributor Author

config toolbar should not be in onAttach since,

  • onAttach(): This is too early in the fragment lifecycle to configure UI elements like the toolbar since the view hasn't been created yet.
  • onCreateView(): The view hierarchy is created here, but it's still not fully initialized. This method is mainly intended for inflating the layout.
  • onViewCreated(): The view is fully initialized at this point, making it the ideal place to set up the toolbar.

@mikehardy
Copy link
Member

Based on that description of the lifecycle, is it possible then that we are in a race with construction of view / configure of toolbar, and a teardown cycle with destroy of view / detach of fragment?

If not, then I don't know how the activity could be null. Perhaps we need some logging on the teardown direction of the view/fragment lifecycle to see if we are still trying to configure a toolbar when the user has already moved on to something else and the fragment detached so there is no activity ?

Copy link
Member

@lukstbit lukstbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the changes, just left two minor style issues.

To be honest, this bug would probably be fixed by using the FragmentResult apis in the configureToolbarInternal() method to ping DeckPicker and let it handle the menu update itself. It's not the job of StudyOptionsFragment to handle the menu of its parent, directly accessing DeckPicker also makes it very hard to test the fragment separately from DeckPicker because any test needs to make sure that the DeckPicker is available or try weird mocking.

I have the same complaint about pushing the handling of those menu items that access directly DeckPicker(deck rename/delete/export) into StudyOptionsFragment.

@lukstbit lukstbit added Needs Author Reply Waiting for a reply from the original author and removed Needs Review labels Oct 22, 2024
@criticalAY criticalAY removed the Needs Author Reply Waiting for a reply from the original author label Oct 22, 2024
@david-allison david-allison added the Review High Priority Request for high priority review label Oct 23, 2024
@david-allison
Copy link
Member

@mikehardy awaiting your review

@david-allison
Copy link
Member

this bug would probably be fixed by using the FragmentResult apis in the configureToolbarInternal() method to ping DeckPicker ...

@lukstbit just to note: the following issue/PR starts to move in this direction, and it'd be useful to transfer the additional thoughts from your comment here so they can be worked into the solution

Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks pretty thorough! There is a small chance acracrium will be bombed with this but somehow I don't think so - hopefully just enough to learn stuff
Thanks @criticalAY

@mikehardy mikehardy added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) squash-merge The pull request currently requires maintainers to "Squash Merge" and removed Review High Priority Request for high priority review Needs Second Approval Has one approval, one more approval to merge labels Oct 24, 2024
@mikehardy mikehardy merged commit 2e1d8bd into ankidroid:main Oct 24, 2024
9 checks passed
@github-actions github-actions bot added this to the 2.19 release milestone Oct 24, 2024
@github-actions github-actions bot removed squash-merge The pull request currently requires maintainers to "Squash Merge" Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) labels Oct 24, 2024
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.

4 participants