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

Crash when pressing search button #6522

Closed
4 tasks done
Douile opened this issue Jun 19, 2021 · 11 comments · Fixed by #6558
Closed
4 tasks done

Crash when pressing search button #6522

Douile opened this issue Jun 19, 2021 · 11 comments · Fixed by #6558
Labels
ASAP Issue needs to be fixed as soon as possible bug Issue is related to a bug

Comments

@Douile
Copy link
Contributor

Douile commented Jun 19, 2021

Checklist

Steps to reproduce the bug

Similar to #6231 but different null pointer exception

0. Build the app from dev branch

  1. Open app
  2. Press search button

Actual behaviour

App crashes (ui error)

Expected behavior

App doesn't crash (no null pointer exception)

Screenshots/Screen recordings

Logs

Exception

  • User Action: ui error
  • Request: ACRA report
  • Content Country: GB
  • Content Language: en-GB
  • App Language: en_GB
  • Service: none
  • Version: 0.21.5
  • OS: Linux Android 11 - 30
Crash log

java.lang.NullPointerException: Attempt to invoke virtual method 'org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory org.schabi.newpipe.extractor.StreamingService.getSearchQHFactory()' on a null object reference
	at org.schabi.newpipe.fragments.list.search.SearchFragment.onCreateOptionsMenu(SearchFragment.java:430)
	at androidx.fragment.app.Fragment.performCreateOptionsMenu(Fragment.java:3100)
	at androidx.fragment.app.FragmentManager.dispatchCreateOptionsMenu(FragmentManager.java:3181)
	at androidx.fragment.app.FragmentController.dispatchCreateOptionsMenu(FragmentController.java:391)
	at androidx.fragment.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:288)
	at androidx.appcompat.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:94)
	at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.onCreatePanelMenu(AppCompatDelegateImpl.java:3070)
	at androidx.appcompat.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:94)
	at androidx.appcompat.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:456)
	at androidx.appcompat.app.ToolbarActionBar$1.run(ToolbarActionBar.java:57)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
	at android.view.Choreographer.doCallbacks(Choreographer.java:796)
	at android.view.Choreographer.doFrame(Choreographer.java:727)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:223)
	at android.app.ActivityThread.main(ActivityThread.java:7660)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)


@Douile Douile added the bug Issue is related to a bug label Jun 19, 2021
@TacoTheDank
Copy link
Member

Are you just using 0.21.5 or did you specifically use the GitHub Action APK build of my PR?

@Douile
Copy link
Contributor Author

Douile commented Jun 19, 2021

I built from remote/dev on the commit specified

@Douile
Copy link
Contributor Author

Douile commented Jun 19, 2021

@TacoTheDank the issue also occurs on the github action build of the PR

@TacoTheDank
Copy link
Member

I see 🤔

However, I don't really see why this could be triggering this bug to occur.

@opusforlife2 Any ideas?

@opusforlife2
Copy link
Collaborator

Wow, dude. I'm flattered, but I'm not a dev. 🤭

@Douile
Copy link
Contributor Author

Douile commented Jun 19, 2021

I did find a "fix" #6394 (comment)

@TacoTheDank
Copy link
Member

TacoTheDank commented Jun 20, 2021

I believe I have made a development.

This bug most likely has to do with two things:

  • How they have rewritten the internals of FragmentManager in AndroidX Fragment 1.3.0.
  • And AndroidX Fragment now uses AndroidX Lifecycle 2.3.1 internally as of 1.3.2, whereas NewPipe itself is still using 2.2.0.

I believe these are the source of this new bug (and may be the cause of possibly undiscovered new bugs as well).

There is likely some new behavior that NewPipe has not sufficiently accounted for, and that is the source of this bug. But, given all the weird shit we have to do around the app just to dispose of stuff properly when views and stuff are destroyed, I suppose this isn't surprising.

But this is the price of progress. If we're too afraid to take risks, we'd never get anywhere 😁

(Btw this bug came about because of the library bumps in #6394)

@opusforlife2
Copy link
Collaborator

@TacoTheDank So should this change be reverted for now, until a solution is found?

Douile added a commit to Douile/NewPipe that referenced this issue Jun 22, 2021
…ragment

It seems due to TeamNewPipe#6394 updating the FragmentX library there was a
change to the order of lifecycle calls, as such onResume() was no longer
before onCreateOptionsMenu() creating a null pointer exception when
using service in onCreateOptionsMenu() as it is only set in onResume().

By moving the initialization of service to onStart() which still happens
before onCreateOptionsMenu() this crash can be avoided. This commit also
adds a check for a null service to prevent future crashes for similar
issues.
@Douile
Copy link
Contributor Author

Douile commented Jun 22, 2021

Observing the logging in this situation the following behavior occurs:

  1. SearchFragment onCreate called
  2. SearchFragment onStart called
  3. SearchFragment onCreateOptionsMenu called (SearchFragment.service used without null check)
  4. SearchFragment onResume called (SearchFragment.service set)

My approach to this would be moving setting the service from onResume to onStart (as per lifecycle docs it seems whenever fragment is displayed onStart then onResume is called) while also null checking in onCreateOptionsMenu. The null check is ultimately unnecessary would prevent crashes for similar issues (although maybe you want a crash so the issue is noticed).

A draft of this fix is here: Douile@384ca66

@B0pol B0pol added the ASAP Issue needs to be fixed as soon as possible label Jun 23, 2021
@B0pol
Copy link
Member

B0pol commented Jun 23, 2021

Can you open a pull request?

@TacoTheDank
Copy link
Member

@opusforlife2 I think it'll be okay. This bump would've needed to be done sooner or later anyway, so it's better that we catch it now. Also, @Douile has made a PR with the fix.

For some reason it didn't occur to me to test the searching function, even though I usually do when making PRs, so this happened to slip by me. Big oops on my part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASAP Issue needs to be fixed as soon as possible bug Issue is related to a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants