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 crashes due to network issue #4

Open
YYYSSSHHH opened this issue Aug 17, 2020 · 2 comments
Open

App crashes due to network issue #4

YYYSSSHHH opened this issue Aug 17, 2020 · 2 comments

Comments

@YYYSSSHHH
Copy link

Environment Info:
APK Version 1.1 (2).
AndroidOS Version = “6.0.1”,Mobile phone has enough memory.

Description information:
We find that mobile apps are prone to crashes due to a network issue, mainly because successful network API calls return unexpected or no data.
And we found that when this app's network returned data is null or some fields are null (JSON format), a random value or the network request fails (status code is 404/503), or is empty, the app has crashed.

crash information:

Crash One:

crashActivity=edu.stanford.rkpandey.covid19tracker.MainActivity

java.lang.OutOfMemoryError: Failed to allocate a 23174278 byte allocation with 16777216 free bytes and 18MB until OOM
at java.lang.StringFactory.newStringFromChars(Native Method)
at java.lang.AbstractStringBuilder.toString(AbstractStringBuilder.java:629)
at java.lang.StringBuilder.toString(StringBuilder.java:663)
at org.json.JSONStringer.toString(JSONStringer.java:430)
at org.json.JSONArray.toString(JSONArray.java:586)
at com.InstrumentClass.typeParser.JsonParser.parseAndFuzz(JsonParser.java:44)
at com.InstrumentClass.ResponseParseAndReplace.parseInputStreamAndAddNode(ResponseParseAndReplace.java:714)
at com.InstrumentClass.ResponseParseAndReplace.parseAndReplace(ResponseParseAndReplace.java:439)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:172)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

Crash Two:

crashActivity=edu.stanford.rkpandey.covid19tracker.MainActivity

java.util.NoSuchElementException: List is empty.
at kotlin.collections.CollectionsKt___CollectionsKt.last(_Collections.kt:372)
at edu.stanford.rkpandey.covid19tracker.MainActivity.updateDisplayMetric(MainActivity.kt:157)
at edu.stanford.rkpandey.covid19tracker.MainActivity.access$updateDisplayMetric(MainActivity.kt:21)
at edu.stanford.rkpandey.covid19tracker.MainActivity$setupEventListeners$3.onCheckedChanged(MainActivity.kt:135)
at android.widget.RadioGroup.setCheckedId(RadioGroup.java:173)
at android.widget.RadioGroup.-wrap0(RadioGroup.java)
at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:351)
at android.widget.CompoundButton.setChecked(CompoundButton.java:159)
at edu.stanford.rkpandey.covid19tracker.MainActivity.updateDisplayWithData(MainActivity.kt:166)
at edu.stanford.rkpandey.covid19tracker.MainActivity.access$updateDisplayWithData(MainActivity.kt:21)
at edu.stanford.rkpandey.covid19tracker.MainActivity$onCreate$1.onResponse(MainActivity.kt:62)
at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1.lambda$onResponse$0$DefaultCallAdapterFactory$ExecutorCallbackCall$1(DefaultCallAdapterFactory.java:89)
at retrofit2.-$$Lambda$DefaultCallAdapterFactory$ExecutorCallbackCall$1$3wC8FyV4pyjrzrYL5U0mlYiviZw.run(lambda)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5539)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)

Crash Three:

crashActivity=edu.stanford.rkpandey.covid19tracker.MainActivity

java.lang.NullPointerException: Attempt to invoke virtual method 'long java.util.Date.getTime()' on a null object reference
at java.util.Calendar.setTime(Calendar.java:1197)
at java.text.SimpleDateFormat.formatImpl(SimpleDateFormat.java:527)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:829)
at java.text.DateFormat.format(DateFormat.java:314)
at edu.stanford.rkpandey.covid19tracker.MainActivity.updateInfoForDate(MainActivity.kt:179)
at edu.stanford.rkpandey.covid19tracker.MainActivity.updateDisplayMetric(MainActivity.kt:157)
at edu.stanford.rkpandey.covid19tracker.MainActivity.access$updateDisplayMetric(MainActivity.kt:21)
at edu.stanford.rkpandey.covid19tracker.MainActivity$setupEventListeners$3.onCheckedChanged(MainActivity.kt:135)
at android.widget.RadioGroup.setCheckedId(RadioGroup.java:173)
at android.widget.RadioGroup.-wrap0(RadioGroup.java)
at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:351)
at android.widget.CompoundButton.setChecked(CompoundButton.java:159)
at edu.stanford.rkpandey.covid19tracker.MainActivity.updateDisplayWithData(MainActivity.kt:166)
at edu.stanford.rkpandey.covid19tracker.MainActivity.access$updateDisplayWithData(MainActivity.kt:21)
at edu.stanford.rkpandey.covid19tracker.MainActivity$onCreate$1.onResponse(MainActivity.kt:62)
at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1.lambda$onResponse$0$DefaultCallAdapterFactory$ExecutorCallbackCall$1(DefaultCallAdapterFactory.java:89)
at retrofit2.-$$Lambda$DefaultCallAdapterFactory$ExecutorCallbackCall$1$3wC8FyV4pyjrzrYL5U0mlYiviZw.run(lambda)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5539)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)

Finally:
The cause of the program crash may be that the network response data is not handled properly in the code, such as null.
Although this kind of collapse is relatively rare, it is also worthy of attention.
If you have confirmed or fixed this problem, please give me a reply, thank you!

@rpandey1234
Copy link
Owner

Thanks for the report! The first issue seems like a standard OOM issue which will happen on certain phones with limited memory. Since the API I'm using doesn't have a way to limit the data, there's not much I can do here.

The 2nd and 3rd issues seem like something I can prevent with more defensive programming. You mention it is relatively rare- can you comment how frequently you're seeing these crashes, and on what phone? Ideally I could find a repro case so I can properly fix it.

@YYYSSSHHH
Copy link
Author

Test information
Thanks for your reply! We are doing a research: "the impact of different network response data on app . To test the robustness of the app. " Because in the real network environment, the app may receive a variety of network response data , so we simulate various network response data, for example: for a normal network response data, we use 404,or null, or random value to replace.
So, the above crashes are also generated by these fuzzy data. When the first crash occurred, I checked that the simulator memory was enough.
From the above description, you can see that we are doing an experimental study to remind developers to pay attention to the weak network or no network environment ,and Pay attention to handling network response data is null or 404 etc.

How to fix it ?
Perhaps you can judge whether it is empty or null when receiving network response data.

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

No branches or pull requests

2 participants