1

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:

  1. Set a breakpoint on "THIS LINE".
  2. Debug App (Shift F9).
  3. Wait for the app to run and stop at the breakpoint.
  4. Step Over (F8)
  5. Remove the breakpoint
  6. 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
Musicslayer
  • 29
  • 1
  • 1
  • I saw the same issue with a more complex (but not recursive) piece of code, where I could place breakpoints in most places as usual, but placing it on a certain line (while execution was paused) triggered the StackOverflowError. I've never seen this in the past 10 years before 2022 - it may be a new bug in Android Studio. In my case, disabling all unneeded breakpoints under Run > View Breakpoints helped. (I tried this because it used to help in a different, older breakpoint-related crash: https://stackoverflow.com/questions/40618803 ) – Attila Tanyi Apr 03 '22 at 18:51

0 Answers0