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

App Crash On Search #2926

Open
1 of 2 tasks
satyajiit opened this issue Nov 18, 2019 · 13 comments · May be fixed by #2928
Open
1 of 2 tasks

App Crash On Search #2926

satyajiit opened this issue Nov 18, 2019 · 13 comments · May be fixed by #2928
Labels

Comments

@satyajiit
Copy link

satyajiit commented Nov 18, 2019

Describe the bug
Clicking on Search Icon in the Toolbar Crash/Terminate the App

To Reproduce

  1. Store an image in the root directory or root of internal i.e /sdcard
  2. Run the App
  3. Click on Search Icon on the Toolbar or Actionbar
  4. App Crash

Expected behavior
Should work normally without crashing the App.

Logs

2019-11-19 05:13:05.307 12660-12660/org.fossasia.phimpme E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.fossasia.phimpme, PID: 12660
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase()' on a null object reference
        at org.fossasia.phimpme.gallery.activities.LFMainActivity.searchTitle(LFMainActivity.java:1712)
        at org.fossasia.phimpme.gallery.activities.LFMainActivity$33.onQueryTextChange(LFMainActivity.java:1645)
        at androidx.appcompat.widget.SearchView.onTextChanged(SearchView.java:1182)
        at androidx.appcompat.widget.SearchView$10.onTextChanged(SearchView.java:1720)
        at android.widget.TextView.sendOnTextChanged(TextView.java:10567)
        at android.widget.TextView.setText(TextView.java:6304)
        at android.widget.TextView.setText(TextView.java:6129)
        at android.widget.EditText.setText(EditText.java:122)
        at android.widget.TextView.setText(TextView.java:6081)
        at androidx.appcompat.widget.SearchView.onActionViewExpanded(SearchView.java:1296)
        at androidx.appcompat.widget.Toolbar$ExpandedActionViewMenuPresenter.expandItemActionView(Toolbar.java:2535)
        at androidx.appcompat.view.menu.MenuBuilder.expandItemActionView(MenuBuilder.java:1366)
        at androidx.appcompat.view.menu.MenuItemImpl.expandActionView(MenuItemImpl.java:830)
        at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:996)
        at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:981)
        at androidx.appcompat.widget.ActionMenuView.invokeItem(ActionMenuView.java:625)
        at androidx.appcompat.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:151)
        at android.view.View.performClick(View.java:7201)
        at android.view.View.performClickInternal(View.java:7170)
        at android.view.View.access$3500(View.java:806)
        at android.view.View$PerformClick.run(View.java:27562)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

GIF
ezgif com-video-to-gif

Screenshots
Screenshot_20191119-050705

Smartphone Info:

Device OnePlus7
Android Version Android 10 OxygenOS 10.0.2

Additional context
The Crash is caused only because album item is returning null when an image is stored in root directory i.e /sdcard .

Would you like to work on the issue?

  • Yes
  • No
@codedsun
Copy link
Contributor

codedsun commented Nov 19, 2019

@satyajiit You mentioned that on clicking the toolbar search option, the app got crashed then how did the null case of album item came up without searching?

Also for me the null case is working on Android 9.

@satyajiit
Copy link
Author

@codedsun The Crash Occurs because of the null value that is being loaded to the album name.
So , when we attempt to iterate to search for the album name it crahes. You can also refer the logs

@codedsun
Copy link
Contributor

codedsun commented Nov 19, 2019

I have also created the same scenario but I found no crash.

As we are searching for string "null" not null type for java, so it wont' crash. And as you said if null would have crashed then the app would have been crashing in prefetching the albums with name null

@yashk2000 Please confirm

@satyajiit
Copy link
Author

@codedsun we cannot apply "toLowerCase" on a null object or datatype right?
This is the issue here.
The normal sequence is when we type something it searches with all the album names ( making the names to lowercase )
So here , when no value is entered in the search ,
When we try to iterate all the album names ( making those album names to lowercase ) , we find such a case that one of the album name has not been initiated which returns null , and applying toLowerCase on that object cause the error.

@satyajiit
Copy link
Author

satyajiit commented Nov 19, 2019

@codedsun while setting the name to textView it converts to "null" string forcefully.
Hence it doesn't crash.
Please refer the Logs.
Not only this will cause error to searching but also to sorting because there we are using comparator to compare between a string and a null value.
Another way to verify is cur.getString(nameColumn) == null return true .
As you can check from the created #2928

@satyajiit
Copy link
Author

The Album name is converted to "null" because of implicit type conversion by Java.
You can check AlbumsAdapter.java ,
for line :
String albumNameHtml = "<i><font color='" + textColor + "'>" + a.getName() + "</font></i>";
As we know null + "String" is going to return "nullString" .
I hope i explained the issue @codedsun 🙂

@codedsun
Copy link
Contributor

@codedsun while setting the name to textView it converts to "null" string forcefully.
Hence it doesn't crash.
Please refer the Logs.
Not only this will cause error to searching but also to sorting because there we are using comparator to compare between a string and a null value.
Another way to verify is cur.getString(nameColumn) == null return true .

The null case is only returned when the media provider class is not able to fetch the name of the album, its not the case when the album name is forcefully set to null it becomes a string automatically. Please check the screenshot it gives me null as a valid string not a NPE.

More reference : https://stackoverflow.com/questions/4802015/difference-between-null-and-empty-java-string

image

The Album name is converted to "null" because of implicit type conversion by Java.
You can check AlbumsAdapter.java ,
for line :
String albumNameHtml = "" + a.getName() + "";
As we know null + "String" is going to return "nullString"

This is a false claim please debug and check what a.getName() returns and add the screenshot here.

Also if this is a device-specific issue I will check and confirm

@satyajiit
Copy link
Author

@codedsun Tested on Devices not running android 10 ,
and found that it loads the name as "0" ,
hence there will be no crash or error.

But on Android 10 devices ( Tested on emulators now ) ,
verified with system logs and crash.
It loads up with null.

@satyajiit
Copy link
Author

@codedsun it is always a good practice to check for null values before using them. right?

@codedsun
Copy link
Contributor

codedsun commented Nov 20, 2019

@satyajiit How is the null folder possible, please mention ? Also please dont edit the issue description. It makes us confuse what we were trying to the actually solve and what you mentioned..

You are saying that we have a folder with no name in sdcard directory, first tell me how is thiss possible until you use some unicode character which arent' visible

Next, if you have a folder named null, then how is the case when we are fetching the same folder with album name throwing NPE.
Also do attatch your screenshots

Please tell me how do I reproduce for android 10 device.

@satyajiit
Copy link
Author

@codedsun Sorry you are getting it wrong.
It might be my poor English.
You don't need to create a null folder.

STEPS TO REPRODUCE

  1. Store any images on the root dir i.e /sdcard ( You can try doing adb push image_name.jpg /sdcard )
  2. Check the app.

What i found :
On android 10 ,
a.getName() returns null.

and on older versions :
returns "0"

@codedsun
Copy link
Contributor

Proceed, Please state the issue clearly. You wrote something else in the issue. No problem
Go Ahead 👍

@Prashant830
Copy link

Can I solve this issues

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.

4 participants