In Android Studio, I created a very small one-activity app:
package com.musicslayer.crashrepro;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
public void helper(){}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Thread(new Runnable() {
@Override
public void run() {
for(int i = 0; i < 40000; i++) { // THIS LINE
helper();
}
}
}).start();
}
}
Whenever I run this code without debugging, it works fine. But now do this:
- Set a breakpoint on "THIS LINE".
- Debug App (Shift F9).
- Wait for the app to run and stop at the breakpoint.
- Step Over (F8)
- Remove the breakpoint
- Resume Program (F9)
The app will crash with this error:
2022-01-25 23:32:04.378 9656-11207/com.musicslayer.crashrepro E/AndroidRuntime: FATAL EXCEPTION: Thread-2
Process: com.musicslayer.crashrepro, PID: 9656
java.lang.StackOverflowError: stack size 1043KB
at com.musicslayer.crashrepro.MainActivity.helper(MainActivity.java:7)
at com.musicslayer.crashrepro.MainActivity$1.run(MainActivity.java:17)
at java.lang.Thread.run(Thread.java:923)
Either I'm missing something obvious here, or something really weird is going on! AFAIK I'm not doing anything recursive, so perhaps it's something artificial that the debugger is causing. Or this is a quirk of Android OS? IDK I'm pretty stumped.
Configuration Info:
Android Studio Arctic Fox | 2020.3.1 Patch 4
In Android Studio:
>> java -version
java version "1.8.0_301"
Java(TM) SE Runtime Environment (build 1.8.0_301-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.301-b09, mixed mode)
I ran the app on a One Plus 8 with Android 11