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

[Bug]: App crashes when you click on Author Name #5187

Closed
shankarpriyank opened this issue Mar 24, 2023 · 22 comments · Fixed by #5199
Closed

[Bug]: App crashes when you click on Author Name #5187

shankarpriyank opened this issue Mar 24, 2023 · 22 comments · Fixed by #5199
Assignees
Labels

Comments

@shankarpriyank
Copy link
Contributor

shankarpriyank commented Mar 24, 2023

Summary

The app crashes when you click on Author Name of an image

Steps to reproduce

  1. Open the app
  2. Skip the login
  3. In the featured tab, open any image
  4. Click on the author name of the image

Expected behaviour

Details about the author should open

Actual behaviour

The app crashes

Device name

POCO X2

Android version

Android 11

Commons app version

4.0.3 prodDebug

Device logs

               fr.free.nrw.commons                  E  ACRA caught a NullPointerException for fr.free.nrw.commons
                                                                            java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                            	at fr.free.nrw.commons.profile.achievements.AchievementsFragment.onCreateView(AchievementsFragment.java:184)
                                                                            	at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2698)
                                                                            	at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:310)
                                                                            	at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1185)
                                                                            	at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1354)
                                                                            	at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1432)
                                                                            	at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1495)
                                                                            	at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
                                                                            	at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2167)
                                                                            	at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1990)
                                                                            	at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1945)
                                                                            	at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1816)
                                                                            	at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:303)
                                                                            	at androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:238)
                                                                            	at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
                                                                            	at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
                                                                            	at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
                                                                            	at android.view.View.measure(View.java:25931)
                                                                            	at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:735)
                                                                            	at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:481)
                                                                            	at android.view.View.measure(View.java:25931)
                                                                            	at androidx.drawerlayout.widget.DrawerLayout.onMeasure(DrawerLayout.java:1119)
                                                                            	at android.view.View.measure(View.java:25931)
                                                                            	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7038)
                                                                            	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                            	at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
                                                                            	at android.view.View.measure(View.java:25931)
                                                                            	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7038)
                                                                            	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
                                                                            	at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
                                                                            	at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
                                                                            	at android.view.View.measure(View.java:25931)
                                                                            	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7038)
                                                                            	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                            	at android.view.View.measure(View.java:25931)
                                                                            	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7038)
                                                                            	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
                                                                            	at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
                                                                            	at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
                                                                            	at android.view.View.measure(View.java:25931)
                                                                            	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7038)
                                                                            	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                            	at com.android.internal.policy.DecorView.onMeasure(DecorView.java:767)
                                                                            	at android.view.View.measure(View.java:25931)
                                                                            	at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3524)
                                                                            	at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2344)
                                                                            	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2605)
                                                                            	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2068)
                                                                            	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8402)
                                                                            	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1058)
                                                                            	at android.view.Choreographer.doCallbacks(Choreographer.java:880)
                                                                            	at android.view.Choreographer.doFrame(Choreographer.java:813)
 7577-7577  ACRA                    fr.free.nrw.commons                  E  	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1043)
                                                                            	at android.os.Handler.handleCallback(Handler.java:938)
                                                                            	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                            	at android.os.Looper.loop(Looper.java:236)
                                                                            	at android.app.ActivityThread.main(ActivityThread.java:7904)
                                                                            	at java.lang.reflect.Method.invoke(Native Method)
                                                                            	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
                                                                            	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

Screen-shots

No response

Would you like to work on the issue?

None

@shankarpriyank shankarpriyank changed the title [Bug]: App crashes when you click on Author Nm [Bug]: App crashes when you click on Author Name Mar 24, 2023
@nicolas-raoul
Copy link
Member

If I understand correctly, tapping works when logged in, but crashes when not logged in? Great find, thanks!

@RitikaPahwa4444
Copy link
Collaborator

This is happening because the achievements section is accessible only to the logged-in users. @nicolas-raoul, what should be the ideal behaviour in this case? Do we intend to make it accessible to everyone?

@nicolas-raoul
Copy link
Member

Crashing is never a good thing.

For non-logged-in users, how about open a web browser on the user's Commons profile page? For instance https://commons.wikimedia.org/wiki/User:Syced

Making it accessible to everyone is another idea, but may be more complex, and non-logged-in users probably do not care much about authors.

@joseearias
Copy link
Contributor

Hi! I would like to work on this issue. Can you assign me this issue? I'm kinda new to contributing to projects but I would like to give it a try.

@nicolas-raoul
Copy link
Member

@joseearias It is yours, thanks! Please let us know about your progress every few days.

@joseearias
Copy link
Contributor

I will, thanks!

@joseearias
Copy link
Contributor

Hi. So then are we agreeing on opening the user details on the device browser for non-logged-in users? I think I know how to solve the problem now.

@nicolas-raoul
Copy link
Member

Yes, thanks!

@joseearias
Copy link
Contributor

Hi. Is there a way to get the user Id through the application? The url of the page works with the id of the user but I can't seem to find a way to access this id in the application. Any guidance of where I could find this?

@RitikaPahwa4444
Copy link
Collaborator

Hi @joseearias, you can try accessing the user from the image information that the application fetches from the API call. ImageInfo.java has a method to access the user (Path: data-client/src/main/java/org/wikipedia/gallery/ImageInfo.java)

@joseearias
Copy link
Contributor

I fixed the error and it doesn't seems to crash anymore. Would it be ok then if when the author's name is clicked the browser opens up a page with the user's profile on https://commons.wikimedia.org?

@nicolas-raoul
Copy link
Member

@joseearias Yes sounds great, looking forward to your pull request :-)

@nicolas-raoul
Copy link
Member

Actually, I am not able to reproduce the crash on master using the steps kindly provided by Priyank.
Am I missing something? Or did the bug get fixed with the recent achievements activity changes?
https://user-images.githubusercontent.com/99590/230619848-e5a36b14-f61c-4dd1-b6cd-cb1db8805fa8.mp4

@shankarpriyank
Copy link
Contributor Author

Umm, that's weird.
The master branch still crashes for me.
I tested on beta and prod debug, it crashes on both.

Screenrecorder-2023-04-07-19-37-40-607.1.mp4

@RitikaPahwa4444
Copy link
Collaborator

Unexpected indeed. What I could interpret from the device logs is that it is throwing a NullPointerException at line number 184 because sessionManager.getUserName() will be null in case the user is not logged in and calling .equals() on it is causing the crash:

@joseearias
Copy link
Contributor

That's strange. It also keeps crashing for me by following the same steps. On both beta and prodDebug.

@shankarpriyank
Copy link
Contributor Author

Unexpected indeed. What I could interpret from the device logs is that it is throwing a NullPointerException at line number 184 because sessionManager.getUserName() will be null in case the user is not logged in and calling .equals() on it is causing the crash:

The more interesting question is why is not crashing for Nicolas

@nicolas-raoul
Copy link
Member

Thanks all for testing! I am using the latest stock Android 13 on Pixel 6.

@RitikaPahwa4444
Copy link
Collaborator

RitikaPahwa4444 commented Apr 8, 2023

The more interesting question is why is not crashing for Nicolas

If the developers aren't handling the exceptions, then I think the behaviour would depend on the device. It would be unexpected; for some the app might crash, for others the device might simply ignore it.

1000048677.mp4

@nicolas-raoul, do the achievements load for you? I tried adding the null check so that the else block executes for me too but this just loads the fragment with the text and icons. The numbers never get fetched and the progress bar keeps spinning. This does not happen in case I am logged in and I can see the numbers and the level badge too.

@RitikaPahwa4444
Copy link
Collaborator

Logged-in Logged-out
logged in logged out

Even the leaderboard does not load for me. The contributions tab works fine, though.

@nicolas-raoul
Copy link
Member

Achievements/leaerboard/contributions all load fine on my device even when not logged in, on the master branch.

Hopefully another core developer can reproduce the crash and test+merge the pull request.

@kartikaykaushik14
Copy link
Contributor

@nicolas-raoul I used Pixel 6 Android 13 and I was able to reproduce the issue and was able to test the fix. Post Fix - The author's page opened as follows -

Screenshot 2023-04-12 at 10 53 11 PM

Screenshot 2023-04-12 at 10 54 35 PM

nicolas-raoul pushed a commit that referenced this issue Apr 13, 2023
* Add conditional on function onAuthorViewClicked for when there's not logged-in user

* Change media.getAuthor() for media.getUser()

* Change hardcoded URL for one given by the BuildConfig object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants