Error de recursión en GUI

Estoy creando una cuadrícula simple de 9x9 para Buscaminas. Una de las funciones principales de este juego es tener una recursión para verificar todos los lados cuando el azulejo al hacer clic no tiene bombas que lo rodeen. En el código adjunto a continuación, he podido crear una función que verifica los lados superior e izquierdo del mosaico. Si agrego más instrucciones, como la parte inferior y la derecha, el programa se bloqueará y no mostrará correctamente los mosaicos. (Verifique el métodocountBorders debajo de la linea//MY MAIN PROBLEM)

// muestra el paquete principal de la GUI Minesweeper4;

public class mainFrame {

public static void main(String[] args) {
    new Grid().setVisible(true);
}

}

// el código principal

package Minesweeper4;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.*;

public class Grid extends JFrame implements ActionListener {

    private JPanel mainGrid;
    private JButton button1, button2;
    private JButton[][] buttons = new JButton[9][9];
    private String[][] mines = new String[9][9];
    private ArrayList<ParentSquare> parentSquare = new ArrayList<ParentSquare>();

    Random rand = new Random();

    NumberSquare numberSquare = new NumberSquare();
    MineSquare mineSquare = new MineSquare();

    public void addMines() {
        for (int j = 0; j < 9; j++) {
            for (int k = 0; k < 9; k++) {
                mines[j][k] = ".";
            }
        }
        for (int i = 0; i < 3; i++) {
            int temp_x = rand.nextInt(9);
            int temp_y = rand.nextInt(9);
            mines[temp_x][temp_y] = "x";
        }
    }

    public void showMines() {
        for (int x = 0; x < 9; x++) {
            for (int y = 0; y < 9; y++) {
                String temp = mines[x][y];
                if (temp.equals("x")) {
                    System.out.println("X: " + (x + 1) + " Y: " + (y + 1) + " Value: " + temp);
                }
            }
        }
    }

    public Grid() {
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(500, 500);
        this.setTitle("Minesweeper 1.0");

        mainGrid = new JPanel();
        mainGrid.setLayout(new GridLayout(9, 9));
        this.add(mainGrid);

        button1 = new JButton("Boop");
        button2 = new JButton("Poop");

        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                buttons[i][j] = new JButton("");
                buttons[i][j].addActionListener(this);
                buttons[i][j].setBackground(Color.GRAY);
            }
        }

        for (int k = 0; k < 9; k++) {
            for (int l = 0; l < 9; l++) {
                mainGrid.add(buttons[k][l]);
            }
        }

        addMines();
        showMines();

    }

    public void countBorders(int x, int y) {
        int UL = 0, UU = 0, UR = 0, LL = 0, RR = 0, DL = 0, DD = 0, DR = 0, SUM = 0;

        if (x > 0) {
            UU = checkTile(x - 1, y);
        }
        if (y > 0) {
            LL = checkTile(x, y - 1);
        }
        if (y < 8) {
            RR = checkTile(x, y + 1);
        }
        if (x < 8) {
            DD = checkTile(x + 1, y);
        }
        if ((x > 0) && (y > 0)) {
            UL = checkTile(x - 1, y - 1);
        }

        if ((x > 0) && (y < 8)) {
            UR = checkTile(x - 1, y + 1);
        }

        if ((x < 8) && (y > 0)) {
            DL = checkTile(x + 1, y - 1);
        }

        if ((x < 8) && (y < 8)) {
            DR = checkTile(x + 1, y + 1);
        }

        SUM = UL + UU + UR + LL + RR + DL + DD + DR;

        printTile(x, y, SUM);

        if (SUM == 0) { //MY MAIN PROBLEM

//            if ((x > 0) && (y > 0)) {countBorders(x-1, y-1);}               //Upper left
            if (x > 0) {
                countBorders(x - 1, y);
            }                 //Upper 
//            if ((x > 0) && (y < 8)) {countBorders(x-1, y+1);}               //Upper right
            if (y > 0) {
                countBorders(x, y - 1);
            }                 //Left
//            if (y < 8)              {countBorders(x, y+1);}                 //Right
//            if ((x < 8) && (y > 0)) {countBorders(x+1, y-1);}               //Down Left
//            if (x < 8)              {countBorders(x+1, y);}                 //Down
//            if ((x < 8) && (y < 8)) {countBorders(x+1, y+1);}               //Down Right
        }

    }

    public void printTile(int x, int y, int SUM) {
        String text = Integer.toString(SUM);
        buttons[x][y].setText(text);
        buttons[x][y].setBackground(Color.CYAN);
    }

    public int checkTile(int x, int y) {
        String c = mines[x][y];
        if (c.equals("x")) {
            return 1;
        } else {
            return 0;
        }
    }

    public void click(int x, int y) {
        String mine = mines[x][y];
        if (mine.equals("x")) {
            System.out.println("Bomb!!!");
            buttons[x][y].setText("!");
            buttons[x][y].setBackground(Color.RED);
        } else {
            countBorders(x, y);
            System.out.println("Safe!!!");
//            buttons[x][y].setText("√");
//            buttons[x][y].setBackground(Color.WHITE);
        }

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (e.getSource() == buttons[i][j]) {
                    System.out.println("Clicked Tile X: " + (i + 1) + " Y: " + (j + 1));
                    //buttons[i][j].setText("!");
                    click(i, j);
                }
            }
        }
    }

}

¿Hay alguna manera de cómo solucionar este problema de recurrencia? Gracias de antemano y realmente estoy tratando de aprender Java. ¡Que tengas un buen día!