Error Help: Cannot access state in VaadinSession or UI without locking the session

Hello everyone.
I have to create a project with Vaadin as part of my studies at university and am now facing a problem.
Since I am not a professional in Vaadin, I have no idea what my error means or how it came about, nor how I can get rid of it.

Perhaps for context: users can send each other friend requests, accept these requests, reject them, etc.
There is a separate view for managing these applications. The functionalities actually all work. However, when I log in to the website with an Incocnito tab with another user while the other window is still open to accept the request, I get the following error message:

There was an exception while trying to navigate to 'friends' with the root cause 'java.lang.IllegalStateException: Cannot access state in VaadinSession or UI without locking the session.'

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'softwareprojekt.spielepartner.views.friends.FriendsView': Failed to instantiate [softwareprojekt.spielepartner.views.friends.FriendsView]: Constructor threw exception 
[...] etc. 

The source code of my friend view looks like this:

@PageTitle("Friends")
@Route(value = "friends", layout = MainLayout.class)
@Uses(Icon.class)
@RolesAllowed({"ADMIN", "USER"})
public class FriendsView extends Composite<HorizontalLayout> {

   private static Grid<UserEntity> friendRequestGrid = new Grid<>(UserEntity.class, false);
    private static Grid<UserEntity> friendsGrid = new Grid<>(UserEntity.class, false);     private static Grid<UserEntity> openFriendsRequestGrid = new Grid<>(UserEntity.class, false);
    private static Grid<UserEntity> blockedUsersGrid = new Grid<>(UserEntity.class, false);

    private static Div noFriendRequestsHint;
    private static Div noFriendsHint; // Neue Div-Komponente für Freundeshinweis
    private final UserService userService;
    private final AuthenticatedUser authenticatedUser;

    private final Button deleteFriendsButton = new Button("Freund entfernen");
    private final Button addFriendRequestButton = new Button("Offene Freundschaftsanfragen verwalten");
    private final Button unblockUsersButton = new Button("Blockierte User wieder freigeben");

    public FriendsView(UserService userService, AuthenticatedUser authenticatedUser) {
        this.userService = userService;
        this.authenticatedUser = authenticatedUser;

        H3 h3 = new H3("Freundesverwaltung");
        h3.setWidth("max-content");

        H3 h31 = new H3("Freundschaftsanfragen");
        h31.setWidth("max-content");

        H5 h5 = new H5("Freunde entfernen");
        h5.setWidth("max-content");

        H5 h51 = new H5("Freundschaftsanfragen an mich");
        h51.setWidth("max-content");

        H5 h52 = new H5("Meine Freunde");
        h52.setWidth("max-content");

        Hr horizontalLine1 = new Hr();
        Hr horizontalLine2 = new Hr();

        HorizontalLayout myFriendsHeaderLayout = new HorizontalLayout();
        myFriendsHeaderLayout.setAlignItems(FlexComponent.Alignment.CENTER);


        deleteFriendsButton.setIcon(new Icon(VaadinIcon.TRASH));
        deleteFriendsButton.addThemeVariants(ButtonVariant.LUMO_ERROR);
        deleteFriendsButton.addClickListener(e -> showDeleteFriendDialog());

        HorizontalLayout friendRequestHeaderLayout = new HorizontalLayout();
        friendRequestHeaderLayout.setAlignItems(FlexComponent.Alignment.CENTER);


        addFriendRequestButton.setIcon(new Icon(VaadinIcon.PENCIL));
        addFriendRequestButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
        addFriendRequestButton.addClickListener(e -> showOpenFriendRequestsDialog());

        unblockUsersButton.setIcon(new Icon(VaadinIcon.UNLOCK));
        unblockUsersButton.addThemeVariants(ButtonVariant.LUMO_SUCCESS);
        unblockUsersButton.addClickListener(e -> unblockUsersDialog());

        getContent().setWidthFull();


        friendRequestGrid.addThemeVariants(GridVariant.LUMO_COMPACT, GridVariant.LUMO_NO_BORDER);
        friendRequestGrid.setWidth("100%");
        friendRequestGrid.getStyle().set("flex-grow", "0");
        setFriendRequestGridData();
        refreshGrid();

        friendsGrid.addThemeVariants(GridVariant.LUMO_COMPACT, GridVariant.LUMO_NO_BORDER); // Konfigurieren des neuen Grid
        friendsGrid.setWidth("100%");
        friendsGrid.getStyle().set("flex-grow", "0");
        setFriendsGridData();
        refreshFriendsGrid();

        //Die Header-Layouts werden mit den jeweiligen Überschriften und Buttons befüllt
        myFriendsHeaderLayout.add(h3, deleteFriendsButton, unblockUsersButton);
        friendRequestHeaderLayout.add(h31, addFriendRequestButton);

        //Das Horizontale Layout der linken Seite wird mit den Komponenten befüllt
        VerticalLayout leftSideVerticalLayout = new VerticalLayout();
        leftSideVerticalLayout.add(myFriendsHeaderLayout);
        leftSideVerticalLayout.add(horizontalLine1);
        leftSideVerticalLayout.add(h52);
        leftSideVerticalLayout.add(friendsGrid); // Hinzufügen des neuen Grid
        leftSideVerticalLayout.add(noFriendsHint); // Hinzufügen des Hinweises, wenn keine Freunde vorhanden sind

        //Das Horizontale Layout der rechten Seite wird mit den Komponenten befüllt.
        VerticalLayout rightSideVerticalLayout = new VerticalLayout();
        rightSideVerticalLayout.add(friendRequestHeaderLayout);
        rightSideVerticalLayout.add(horizontalLine2);
        rightSideVerticalLayout.add(h51);
        rightSideVerticalLayout.add(friendRequestGrid);
        rightSideVerticalLayout.add(noFriendRequestsHint);


        getContent().add(leftSideVerticalLayout, rightSideVerticalLayout);

    }

    private void friendSelect(Select<UserEntity> select) {
        authenticatedUser.get().ifPresent(user -> {
            List<UserEntity> friends = userService.getFreunde(user.getId());
            select.setItems(friends);
            select.setItemLabelGenerator(friend -> friend.getVorname() + " " + friend.getName() + " (" + friend.getUserCode() + ")");
        });
    }

    // Hilfsmethode zum Erstellen eines Containers mit drei Buttons
    private HorizontalLayout createButtonContainer(UserEntity userEntity) {
        HorizontalLayout buttonContainer = new HorizontalLayout();
        for (int i = 0; i < 3; i++) {
            Button button = new Button();
            button.addThemeVariants(ButtonVariant.LUMO_ICON, ButtonVariant.LUMO_TERTIARY);
            switch (i) {
                case 0:
                    button.setIcon(new Icon(VaadinIcon.CHECK));
                    button.addClickListener(e -> this.approveFriendshipRequest(userEntity));
                    button.addThemeVariants(ButtonVariant.LUMO_SUCCESS);
                    button.setTooltipText("Anfrage annehmen");
                    break;
                case 1:
                    button.setIcon(new Icon(VaadinIcon.TRASH));
                    button.addClickListener(e -> this.declineFriendshipRequest(userEntity)); // Aufruf der Methode zum Ablehnen
                    button.addThemeVariants(ButtonVariant.LUMO_ERROR);
                    button.setTooltipText("Anfrage ablehnen");
                    break;
                case 2:
                    button.setIcon(new Icon(VaadinIcon.CLOSE));
                    button.addClickListener(e -> this.blockUser(userEntity)); // Aufruf der Methode zum Blockieren
                    button.addThemeVariants(ButtonVariant.LUMO_ERROR);
                    button.setTooltipText("User blockieren");
                    break;
            }
            buttonContainer.add(button);
        }
        return buttonContainer;
    }

    private void setFriendRequestGridData() {
        friendRequestGrid.addColumn(UserEntity::getUserCode).setHeader("Benutzer-ID");
        friendRequestGrid.addColumn(UserEntity::getVorname).setHeader("Vorname");
        friendRequestGrid.addColumn(UserEntity::getName).setHeader("Nachname");
        friendRequestGrid.addColumn(new ComponentRenderer<>(this::createButtonContainer)).setHeader("Anfrage bearbeiten");

        authenticatedUser.get().ifPresent(user -> {
            friendRequestGrid.setItems(userService.getAngefragtVon(user.getId()));
        });

        noFriendRequestsHint = new Div();
        noFriendRequestsHint.setText("Du hast keine offenen Freundschaftsanfragen.");
        noFriendRequestsHint.getStyle().set("padding", "var(--lumo-size-l)")
                .set("text-align", "center").set("font-style", "italic")
                .set("color", "var(--lumo-contrast-70pct)");
    }

    private void setFriendsGridData() {
        friendsGrid.addColumn(UserEntity::getUserCode).setHeader("Benutzer-ID");
        friendsGrid.addColumn(UserEntity::getVorname).setHeader("Vorname");
        friendsGrid.addColumn(UserEntity::getName).setHeader("Nachname");

        noFriendsHint = new Div();
        noFriendsHint.setText("Du hast noch keine Freunde.");
        noFriendsHint.getStyle().set("padding", "var(--lumo-size-l)")
                .set("text-align", "center").set("font-style", "italic")
                .set("color", "var(--lumo-contrast-70pct)");
    }

    private void refreshGrid() {
        authenticatedUser.get().ifPresent(user -> {
            if (userService.getAngefragtVon(user.getId()).size() > 0) {
                friendRequestGrid.setVisible(true);
                noFriendRequestsHint.setVisible(false);
                friendRequestGrid.getDataProvider().refreshAll();
            } else {
                friendRequestGrid.setVisible(false);
                noFriendRequestsHint.setVisible(true);
            }
        });
    }

    private void refreshFriendsGrid() {
        authenticatedUser.get().ifPresent(user -> {
            List<UserEntity> friends = userService.getFreunde(user.getId());
            if (friends.isEmpty()) {
                friendsGrid.setVisible(false);
                noFriendsHint.setVisible(true);
            } else {
                friendsGrid.setItems(friends);
                friendsGrid.setVisible(true);
                noFriendsHint.setVisible(false);
            }
        });
    }

    public void approveFriendshipRequest(UserEntity anfrager) {
        authenticatedUser.get().ifPresent(user -> {
            if (anfrager == null)
                return;
            userService.anfrageAnnehmen(user.getId(), anfrager.getId());
            this.refreshGrid();
            this.refreshFriendsGrid(); // Freunde-Grid aktualisieren
            Notification successNotification = NotificationService.buildSuccessNotification("Anfrage" + anfrager.getUserCode() + " genehmigt", null);
            successNotification.open();
        });
    }

    public void declineFriendshipRequest(UserEntity anfrager) {
        authenticatedUser.get().ifPresent(user -> {
            if (anfrager == null)
                return;
            userService.anfrageAblehnen(user.getId(), anfrager.getId());
            this.refreshGrid();
            Notification errorNotification = NotificationService.buildErrorNofification("Anfrage " + anfrager.getUserCode() + " abgelehnt", null);
            errorNotification.open();
        });
    }

    public void blockUser(UserEntity anfrager) {
        authenticatedUser.get().ifPresent(user -> {
            if (anfrager == null)
                return;
            userService.blockUser(user.getId(), anfrager.getId());
            this.refreshGrid();
            Notification successNotification = NotificationService.buildSuccessNotification("User " + anfrager.getUserCode() + " blockiert", null);
            successNotification.open();
        });
    }

    private void removeSelectedFriend(UserEntity selectedFriend) {
        authenticatedUser.get().ifPresent(user -> {
            if (selectedFriend != null) {
                userService.removeFriend(user.getId(), selectedFriend.getId());
                this.refreshFriendsGrid();
                Notification successNotification = NotificationService.buildSuccessNotification("Freund " + selectedFriend.getUserCode() + " entfernt", null);
                successNotification.open();
            } else {
                Notification errorNotification = NotificationService.buildErrorNofification("Kein Freund ausgewählt", null);
                errorNotification.open();
            }
        });
    }

    private void showOpenFriendRequestsDialog(){
        Dialog openFriendsRequestDialog = new Dialog();
        openFriendsRequestDialog.setHeaderTitle("Offene Freundschaftsanfragen verwalten");
        openFriendsRequestDialog.setCloseOnEsc(false);
        openFriendsRequestDialog.setCloseOnOutsideClick(false);
        openFriendsRequestDialog.setWidth("80%");
        VerticalLayout dialogLayout = new VerticalLayout();

        Button addFriendRequestButton = new Button("Freundschaftsanfrage senden");
        addFriendRequestButton.setIcon(new Icon(VaadinIcon.PLUS));
        addFriendRequestButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
        addFriendRequestButton.addClickListener(e -> showSendFriendRequestDialog());

        Button closeButton = new Button("Schließen", event -> openFriendsRequestDialog.close());
        closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);

        openFriendsRequestDialog.getFooter().add(closeButton, addFriendRequestButton);

        openFriendsRequestGrid.addThemeVariants(GridVariant.LUMO_COMPACT, GridVariant.LUMO_NO_BORDER);
        openFriendsRequestGrid.setWidthFull();
        openFriendsRequestGrid.addColumn(UserEntity::getUserCode).setHeader("Benutzer-ID");
        openFriendsRequestGrid.addColumn(UserEntity::getVorname).setHeader("Vorname");
        openFriendsRequestGrid.addColumn(UserEntity::getName).setHeader("Nachname");
        openFriendsRequestGrid.addColumn(new ComponentRenderer<>(userEntity -> {
            Button undoRequestButton = new Button(new Icon(VaadinIcon.ARROW_BACKWARD));
            undoRequestButton.addClickListener(e -> {
                undoFriendRequest(userEntity);
                populateOpenFriendsRequestGrid(openFriendsRequestGrid);
            });
            undoRequestButton.setTooltipText("Freundschaftsanfrage zurückziehen");
            return undoRequestButton;
        })).setHeader("Anfrage zurückziehen");

        populateOpenFriendsRequestGrid(openFriendsRequestGrid);

        dialogLayout.add(openFriendsRequestGrid);
        openFriendsRequestDialog.add(dialogLayout);
        openFriendsRequestDialog.open();
    }

    private void populateOpenFriendsRequestGrid(Grid<UserEntity> openFriendsRequestGrid) {
        authenticatedUser.get().ifPresent(user -> {
            List<UserEntity> openFriendRequests = userService.getAngefragtAn(user.getId());
            openFriendsRequestGrid.setItems(openFriendRequests);
        });
    }

    private void undoFriendRequest(UserEntity userEntity) {
        authenticatedUser.get().ifPresent(user -> {
            if (userEntity != null) {
                userService.undoFriendRequest(user.getId(), userEntity.getId());
                this.refreshGrid();
                this.refreshFriendsGrid();
                Notification successNotification = NotificationService.buildSuccessNotification("Freundschaftsanfrage an " + userEntity.getUserCode() + " zurückgezogen", null);
                successNotification.open();
            } else {
                Notification errorNotification = NotificationService.buildErrorNofification("Kein Benutzer ausgewählt", null);
                errorNotification.open();
            }
        });
    }

    private void showSendFriendRequestDialog() {
        Dialog sendFriendRequestDialog = new Dialog();
        sendFriendRequestDialog.setHeaderTitle("Freundschaftsanfrage senden");
        sendFriendRequestDialog.setCloseOnEsc(false);
        sendFriendRequestDialog.setCloseOnOutsideClick(false);
        VerticalLayout dialogLayout = new VerticalLayout();

        Button cancelButton = new Button("Abbrechen", event -> sendFriendRequestDialog.close());
        Button buttonSendRequest = new Button("Anfrage senden");
        sendFriendRequestDialog.getFooter().add(cancelButton, buttonSendRequest);

        TextField textFieldRequestId = new TextField("Benutzer-ID");
        textFieldRequestId.setPlaceholder("Benutzer-ID eingeben");
        textFieldRequestId.setWidthFull();
        textFieldRequestId.setInvalid(true);
        textFieldRequestId.setErrorMessage("Bitte eingabe tätigen");

        buttonSendRequest.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
        buttonSendRequest.addClickListener(e -> {
            if (!userService.existsByUserCode(textFieldRequestId.getValue())) {
                textFieldRequestId.setInvalid(true);
                textFieldRequestId.setErrorMessage("Benutzer-ID nicht gefunden");
                textFieldRequestId.setValue("");
            } else if (textFieldRequestId.getValue().equals(authenticatedUser.get().get().getUserCode())) {
                textFieldRequestId.setInvalid(true);
                textFieldRequestId.setErrorMessage("Du kannst dir keine Freundschaftsanfrage senden");
                textFieldRequestId.setValue("");
            } else {
                userService.saveUserAnfrage(authenticatedUser.get().get(), userService.findUserByUserCode(textFieldRequestId.getValue()));
                Notification successNotification = NotificationService.buildSuccessNotification("Freundschaftsanfrage erfolgreich gesendet", null);
                successNotification.open();
                textFieldRequestId.setValue("");
                sendFriendRequestDialog.close();
                populateOpenFriendsRequestGrid(openFriendsRequestGrid);
            }
        });

        dialogLayout.add(textFieldRequestId);
        sendFriendRequestDialog.add(dialogLayout);
        sendFriendRequestDialog.open();
    }

    private void showDeleteFriendDialog(){
        Dialog deleteFriendsDialog = new Dialog();
        deleteFriendsDialog.setHeaderTitle("Freundschaftsanfrage senden");
        deleteFriendsDialog.setCloseOnEsc(false);
        deleteFriendsDialog.setCloseOnOutsideClick(false);
        VerticalLayout dialogLayout = new VerticalLayout();

        Button deleteFriendButton = new Button("Freund entfernen");
        deleteFriendButton.addThemeVariants(ButtonVariant.LUMO_ERROR);
        Button cancelButton = new Button("Abbrechen", event -> deleteFriendsDialog.close());
        cancelButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);

        deleteFriendsDialog.getFooter().add(cancelButton, deleteFriendButton);

        Select<UserEntity> myFriendsselect = new Select<>();
        myFriendsselect.setLabel("Freund auswählen");

        friendSelect(myFriendsselect);

        deleteFriendButton.addClickListener(e -> {
            removeSelectedFriend(myFriendsselect.getValue());
            deleteFriendsDialog.close();
        });

        dialogLayout.add(myFriendsselect);
        deleteFriendsDialog.add(dialogLayout);
        deleteFriendsDialog.open();
    }

    private void unblockUsersDialog() {
        Dialog unblockUsersDialog = new Dialog();
        unblockUsersDialog.setHeaderTitle("Blockierte User wieder freigeben");
        unblockUsersDialog.setCloseOnEsc(false);
        unblockUsersDialog.setCloseOnOutsideClick(false);
        unblockUsersDialog.setWidth("80%");
        VerticalLayout dialogLayout = new VerticalLayout();

        Button closeButton = new Button("Schließen", event -> unblockUsersDialog.close());
        closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);

        unblockUsersDialog.getFooter().add(closeButton);

        blockedUsersGrid.addThemeVariants(GridVariant.LUMO_COMPACT, GridVariant.LUMO_NO_BORDER);
        blockedUsersGrid.setWidthFull();
        blockedUsersGrid.addColumn(UserEntity::getUserCode).setHeader("Benutzer-ID");
        blockedUsersGrid.addColumn(UserEntity::getVorname).setHeader("Vorname");
        blockedUsersGrid.addColumn(UserEntity::getName).setHeader("Nachname");
        blockedUsersGrid.addColumn(new ComponentRenderer<>(userEntity -> {
            Button undoRequestButton = new Button(new Icon(VaadinIcon.CHECK));
            undoRequestButton.addClickListener(e -> {
                userService.unblockUser(authenticatedUser.get().get().getId(), userEntity.getId());
                populateBlockedUsersGrid(blockedUsersGrid);
            });
            undoRequestButton.setTooltipText("Blockierung des User wieder aufheben aufheben");
            return undoRequestButton;
        })).setHeader("Blockierung aufheben");

        populateBlockedUsersGrid(blockedUsersGrid);


        dialogLayout.add(blockedUsersGrid);


        unblockUsersDialog.add(dialogLayout);
        unblockUsersDialog.open();
    }

    private void populateBlockedUsersGrid(Grid<UserEntity> blockedUsersGrid) {
        authenticatedUser.get().ifPresent(user -> {
            List<UserEntity> blockedUsers = userService.getBlockedUsers(user.getId());
            blockedUsersGrid.setItems(blockedUsers);
        });
    }
}

Since I currently suspect that the problem has something to do with the UserService, here is the code for that:

@Service
public class UserService {

    private final UserEntityRepository repository;
    private final BefreundetRepository befreundetRepository;
    private final BlockedEntityRepository blockedEntityRepository;


    @Autowired
    public UserService(UserEntityRepository repository, BefreundetRepository befreundetRepository,BlockedEntityRepository blockedEntityRepository  ) {
        this.repository = repository;
        this.befreundetRepository = befreundetRepository;
        this.blockedEntityRepository = blockedEntityRepository;
    }

    public Optional<UserEntity> get(Long id) {
        return repository.findById(id);
    }

    public UserEntity update(UserEntity entity) {
        return repository.save(entity);
    }

    public void delete(Long id) {
        repository.deleteById(id);
    }

    public Page<UserEntity> list(Pageable pageable) {
        return repository.findAll(pageable);
    }

    public Page<UserEntity> list(Pageable pageable, Specification<UserEntity> filter) {
        return repository.findAll(filter, pageable);
    }

    public int count() {
        return (int) repository.count();
    }
    public UserEntity createUser(String userCode, String name, String vorname, String email, String hashedPassword, Set<Role> roles) {
        UserEntity user = new UserEntity();
        user.setUserCode(userCode);
        user.setName(name);
        user.setVorname(vorname);
        user.setEmail(email);
        user.setHashedPassword(hashedPassword);
        user.setRoles(roles != null ? roles : new HashSet<>());

        return repository.save(user);
    }

    @Transactional(readOnly = true)
    public UserEntity findUserByEmailAndConfirmationCode(String email, String confirmationCode) {
        return repository.findByEmailAndConfirmationCode(email, confirmationCode).orElse(null);
    }
    public UserEntity findUserByEmail(String email) {
        return repository.findByEmail(email);
    }

    @Transactional(readOnly = true)
    public boolean existsByEmail(String email) {
        return repository.existsByEmail(email);
    }

    @Transactional(readOnly = true)
    public boolean existsnotByEmail(String email) {
        boolean wahrheit = repository.existsByEmail(email);
        if(wahrheit == true){
            return false;
        }else{
            return true;
        }

    }

    @Transactional(readOnly = true)
    public boolean existsByUserCode(String userCode) {
        return repository.existsByUserCode(userCode);
    }

    public UserEntity findUserByUserCode(String userCode) {
        return repository.findByUserCode(userCode);
    }

    @Transactional
    public void saveUserAnfrage(UserEntity user, UserEntity angefragterUser) {
        // Stellen Sie sicher, dass die übergebenen UserEntity-Objekte verwaltet sind
        user = repository.findById(user.getId()).orElseThrow(() -> new EntityNotFoundException("User not found"));
        angefragterUser = repository.findById(angefragterUser.getId()).orElseThrow(() -> new EntityNotFoundException("Requested user not found"));

        user.addAnfrage(angefragterUser);
        repository.save(user);
    }

    @Transactional(readOnly = true)
    public Set<UserEntity> getAngefragtVon(long userId) {
        UserEntity user = repository.findById(userId).orElseThrow(() -> new EntityNotFoundException("User not found"));
        return user.getAngefragtVon();
    }

    @Transactional(readOnly = true)
    public List<UserEntity> getAngefragtAn(long userId) {
        UserEntity user = repository.findById(userId).orElseThrow(() -> new EntityNotFoundException("User not found"));
        return user.getAnfrage().stream().collect(Collectors.toList());
    }

    @Transactional
    public void anfrageAnnehmen(long userId, long anfragerId) {
        UserEntity user = repository.findById(userId).orElseThrow(() -> new EntityNotFoundException("User not found"));
        UserEntity anfrager = repository.findById(anfragerId).orElseThrow(() -> new EntityNotFoundException("Anfrager not found"));

        System.out.println("User ID: " + user.getId());
        System.out.println("Anfrager ID: " + anfrager.getId());
        System.out.println("User: " + user.toString());
        System.out.println("Anfrager: " + anfrager.toString());

        if (user == null || anfrager == null) {
            throw new IllegalStateException("User or Anfrager is null");
        }

        anfrager.removeAnfrage(user);
        repository.save(anfrager);

        BefreundetEntity befreundetEntity1 = new BefreundetEntity();
        befreundetEntity1.setUser(user);
        befreundetEntity1.setFreund(anfrager);

        BefreundetEntity befreundetEntity2 = new BefreundetEntity();
        befreundetEntity2.setUser(anfrager);
        befreundetEntity2.setFreund(user);

        if (befreundetEntity1.getUser() == null || befreundetEntity1.getFreund() == null ||
                befreundetEntity2.getUser() == null || befreundetEntity2.getFreund() == null) {
            throw new IllegalStateException("BefreundetEntity has null user or freund");
        }

        user.addFreund(befreundetEntity1);
        anfrager.addFreund(befreundetEntity2);

        befreundetRepository.save(befreundetEntity1);
        befreundetRepository.save(befreundetEntity2);

        repository.save(user);
        repository.save(anfrager);
    }

    @Transactional(readOnly = true)
    public List<UserEntity> getFreunde(long userId) {
        UserEntity user = repository.findById(userId).orElseThrow(() -> new EntityNotFoundException("User not found"));
        return user.getFreunde().stream().map(BefreundetEntity::getFreund).collect(Collectors.toList());
    }

    //Löscht Freund aus Liste
    @Transactional
    public void removeFriend(long userId, long friendId) {
        UserEntity user = repository.findById(userId).orElseThrow(() -> new EntityNotFoundException("User not found"));
        UserEntity friend = repository.findById(friendId).orElseThrow(() -> new EntityNotFoundException("Friend not found"));

        BefreundetEntity befreundetEntity = befreundetRepository.findByUserAndFreund(user, friend);
        if (befreundetEntity != null) {
            befreundetRepository.delete(befreundetEntity);
        }

        BefreundetEntity inverseBefreundetEntity = befreundetRepository.findByUserAndFreund(friend, user);
        if (inverseBefreundetEntity != null) {
            befreundetRepository.delete(inverseBefreundetEntity);
        }
    }

    @Transactional
    public void anfrageAblehnen(long userId, long anfragerId) {
        UserEntity user = repository.findById(userId)
                .orElseThrow(() -> new EntityNotFoundException("User not found"));
        UserEntity anfrager = repository.findById(anfragerId)
                .orElseThrow(() -> new EntityNotFoundException("Anfrager not found"));

        // Anfrage entfernen
        anfrager.removeAnfrage(user);
        repository.save(anfrager);
    }

    @Transactional
    public void blockUser(long userId, long anfragerId) {
        UserEntity user = repository.findById(userId)
                .orElseThrow(() -> new EntityNotFoundException("User not found"));
        UserEntity anfrager = repository.findById(anfragerId)
                .orElseThrow(() -> new EntityNotFoundException("Anfrager not found"));

        // Anfrage entfernen
        anfrager.removeAnfrage(user);
        repository.save(anfrager);

        // Blockierung speichern
        BlockedEntity blockedEntity = new BlockedEntity();
        blockedEntity.setUser(user);
        blockedEntity.setBlockedUser(anfrager);
        blockedEntityRepository.save(blockedEntity);
    }

    @Transactional
    public void undoFriendRequest(long userId, long friendId) {
        UserEntity user = repository.findById(userId).orElseThrow(() -> new EntityNotFoundException("User not found"));
        UserEntity friend = repository.findById(friendId).orElseThrow(() -> new EntityNotFoundException("Friend not found"));
        user.getAnfrage().remove(friend);
        repository.save(user);
    }

    @Transactional(readOnly = true)
    public List<UserEntity> getBlockedUsers(long userId) {
        UserEntity user = repository.findById(userId).orElseThrow(() -> new EntityNotFoundException("User not found"));
        return new ArrayList<>(user.getBlocked_users());
    }

    @Transactional
    public void unblockUser(long userId, long blockedUserId) {
        UserEntity user = repository.findById(userId).orElseThrow(() -> new EntityNotFoundException("User not found"));
        UserEntity blockedUser = repository.findById(blockedUserId).orElseThrow(() -> new EntityNotFoundException("Blocked user not found"));
        user.getBlocked_users().remove(blockedUser);
        repository.save(user);
    }

    public String generateUniqueRandomCode(int length) {
        String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuilder code = new StringBuilder();

        // Überprüfen, ob der generierte Code bereits in der Datenbank vorhanden ist
        do {
            code.setLength(0); // Zurücksetzen des StringBuilder
            for (int i = 0; i < length; i++) {
                int index = random.nextInt(characters.length());
                code.append(characters.charAt(index));
            }
        } while (repository.existsByUserCode(code.toString()));

        return code.toString();
    }

}

I hope I’ve come to the right place with my request. In any case, I would be very grateful if someone could help me.

…and sorry for some of the bad English. :slight_smile:

The etc is needed to find the problematic line before searching in hundreds of lines :slightly_smiling_face:

Using static fields to store component references could be a culprit.

 private static Grid<UserEntity> friendRequestGrid

But, as Knoobie said, the full stack-trace would definitely help in investigation

Oh. If it’s more important to see the complete error message, I’ll attach it here:

2024-06-03T17:32:33.609+02:00 ERROR 22796 --- [nio-8080-exec-1] c.v.flow.router.InternalServerError      : There was an exception while trying to navigate to 'friends'

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'softwareprojekt.spielepartner.views.friends.FriendsView': Failed to instantiate [softwareprojekt.spielepartner.views.friends.FriendsView]: Constructor threw exception
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:318) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:306) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1355) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1192) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:321) ~[spring-beans-6.1.6.jar:6.1.6]
	at com.vaadin.flow.spring.SpringInstantiator.getOrCreate(SpringInstantiator.java:127) ~[vaadin-spring-24.3.10.jar:na]
	at com.vaadin.flow.di.Instantiator.createRouteTarget(Instantiator.java:169) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.lambda$getRouteTarget$1(AbstractNavigationStateRenderer.java:133) ~[flow-server-24.3.10.jar:24.3.10]
	at java.base/java.util.Optional.orElseGet(Optional.java:364) ~[na:na]
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.getRouteTarget(AbstractNavigationStateRenderer.java:132) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.sendBeforeEnterEventAndPopulateChain(AbstractNavigationStateRenderer.java:481) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.createChainIfEmptyAndExecuteBeforeEnterNavigation(AbstractNavigationStateRenderer.java:462) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.handle(AbstractNavigationStateRenderer.java:212) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.component.internal.JavaScriptNavigationStateRenderer.handle(JavaScriptNavigationStateRenderer.java:78) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.component.UI.handleNavigation(UI.java:1853) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.component.UI.renderViewForRoute(UI.java:1816) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.component.UI.lambda$connectClient$83bb1bf7$1(UI.java:1724) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.component.UI.connectClient(UI.java:1734) ~[flow-server-24.3.10.jar:24.3.10]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
	at com.vaadin.flow.server.communication.rpc.PublishedServerEventHandlerRpcHandler.invokeMethod(PublishedServerEventHandlerRpcHandler.java:227) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.server.communication.rpc.PublishedServerEventHandlerRpcHandler.invokeMethod(PublishedServerEventHandlerRpcHandler.java:204) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.server.communication.rpc.PublishedServerEventHandlerRpcHandler.invokeMethod(PublishedServerEventHandlerRpcHandler.java:150) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.server.communication.rpc.PublishedServerEventHandlerRpcHandler.handleNode(PublishedServerEventHandlerRpcHandler.java:133) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.server.communication.rpc.AbstractRpcInvocationHandler.handle(AbstractRpcInvocationHandler.java:74) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocationData(ServerRpcHandler.java:466) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.server.communication.ServerRpcHandler.lambda$handleInvocations$4(ServerRpcHandler.java:447) ~[flow-server-24.3.10.jar:24.3.10]
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596) ~[na:na]
	at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:447) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:324) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:114) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1574) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:398) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.spring.SpringServlet.service(SpringServlet.java:106) ~[vaadin-spring-24.3.10.jar:na]
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658) ~[tomcat-embed-core-10.1.20.jar:6.0]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:150) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:653) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:419) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:313) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:277) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.springframework.web.servlet.mvc.ServletForwardingController.handleRequestInternal(ServletForwardingController.java:142) ~[spring-webmvc-6.1.6.jar:6.1.6]
	at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:178) ~[spring-webmvc-6.1.6.jar:6.1.6]
	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:51) ~[spring-webmvc-6.1.6.jar:6.1.6]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1089) ~[spring-webmvc-6.1.6.jar:6.1.6]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979) ~[spring-webmvc-6.1.6.jar:6.1.6]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) ~[spring-webmvc-6.1.6.jar:6.1.6]
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:914) ~[spring-webmvc-6.1.6.jar:6.1.6]
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590) ~[tomcat-embed-core-10.1.20.jar:6.0]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885) ~[spring-webmvc-6.1.6.jar:6.1.6]
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658) ~[tomcat-embed-core-10.1.20.jar:6.0]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:150) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) ~[tomcat-embed-websocket-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:175) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:150) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:108) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.security.web.FilterChainProxy.lambda$doFilterInternal$3(FilterChainProxy.java:231) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:365) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.access.intercept.AuthorizationFilter.doFilter(AuthorizationFilter.java:100) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:126) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:120) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:100) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:179) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:227) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:221) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:107) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:93) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:117) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:91) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.context.SecurityContextHolderFilter.doFilter(SecurityContextHolderFilter.java:82) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.context.SecurityContextHolderFilter.doFilter(SecurityContextHolderFilter.java:69) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:62) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.session.DisableEncodeUrlFilter.doFilterInternal(DisableEncodeUrlFilter.java:42) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:233) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:191) ~[spring-security-web-6.2.4.jar:6.2.4]
	at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:113) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.web.servlet.handler.HandlerMappingIntrospector.lambda$createCacheFilter$3(HandlerMappingIntrospector.java:195) ~[spring-webmvc-6.1.6.jar:6.1.6]
	at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:113) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:74) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration$CompositeFilterChainProxy.doFilter(WebMvcSecurityConfiguration.java:230) ~[spring-security-config-6.2.4.jar:6.2.4]
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:352) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:268) ~[spring-web-6.1.6.jar:6.1.6]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:175) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:150) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.6.jar:6.1.6]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:175) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:150) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.6.jar:6.1.6]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:175) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:150) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.6.jar:6.1.6]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:175) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:150) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [softwareprojekt.spielepartner.views.friends.FriendsView]: Constructor threw exception
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:221) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:111) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:315) ~[spring-beans-6.1.6.jar:6.1.6]
	... 136 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot access state in VaadinSession or UI without locking the session.
	at com.vaadin.flow.server.VaadinSession.checkHasLock(VaadinSession.java:572) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.server.VaadinSession.checkHasLock(VaadinSession.java:586) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.internal.StateTree.checkHasLock(StateTree.java:454) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.internal.StateTree.markAsDirty(StateTree.java:305) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.internal.StateNode.markAsDirty(StateNode.java:608) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.internal.nodefeature.NodeList.addChange(NodeList.java:276) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.internal.nodefeature.NodeList.add(NodeList.java:237) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.internal.nodefeature.StateNodeNodeList.add(StateNodeNodeList.java:54) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.internal.nodefeature.ElementChildrenList.add(ElementChildrenList.java:44) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.dom.impl.AbstractNodeStateProvider.insertChild(AbstractNodeStateProvider.java:107) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.dom.Node.insertChild(Node.java:391) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.dom.Node.appendChild(Node.java:163) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.dom.Node.appendChild(Node.java:147) ~[flow-server-24.3.10.jar:24.3.10]
	at com.vaadin.flow.component.grid.Grid.addColumn(Grid.java:1999) ~[vaadin-grid-flow-24.3.12.jar:na]
	at com.vaadin.flow.component.grid.Grid.addColumn(Grid.java:1801) ~[vaadin-grid-flow-24.3.12.jar:na]
	at com.vaadin.flow.component.grid.Grid.addColumn(Grid.java:1767) ~[vaadin-grid-flow-24.3.12.jar:na]
	at softwareprojekt.spielepartner.views.friends.FriendsView.setFriendRequestGridData(FriendsView.java:183) ~[classes/:na]
	at softwareprojekt.spielepartner.views.friends.FriendsView.<init>(FriendsView.java:109) ~[classes/:na]
	at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) ~[na:na]
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) ~[na:na]
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) ~[na:na]
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:208) ~[spring-beans-6.1.6.jar:6.1.6]
	... 138 common frames omitted

There are the lines pointing in the direction of the culprit… but Marco was already nice enough to search your whole class and found the culprit by hand :man_bowing:

So to clarify, the problem here is most likely that those UI component instances are stored in a static class field. This means that the framework will try to use the same component instance for all users.

Sharing instances in this way can cause various weird errors and in this case the trigger is when a component associated with the session of user A is used by user B since then the B session is locked but the A session is not locked but the component instance expects the A session to be locked since that component is associated with that session.