IllegalStateException with Timer issue?

I have a screen opened by another:

OrderScreen orderScreen = screenBuilders.screen(this)
        .withScreenClass(OrderScreen.class)
        .withAfterCloseListener(orderScreenAfterScreenCloseEvent -> {

            if (orderScreenAfterScreenCloseEvent.getCloseAction().equals(WINDOW_COMMIT_AND_CLOSE_ACTION)) {
                refreshData();
            }
        })
        .build();

orderScreen.setParentDataContext(dataContext);
orderScreen.setTableItem(selectedTable, null);
orderScreen.show();

when I close it I get this error:

java.lang.IllegalStateException: An extension can not be set to extend a new target after getting detached from the previous.
	at com.vaadin.server.AbstractExtension.setParent(AbstractExtension.java:88)
	at com.vaadin.server.AbstractClientConnector.addExtension(AbstractClientConnector.java:610)
	at com.vaadin.server.AbstractExtension.extend(AbstractExtension.java:77)
	at com.haulmont.cuba.web.widgets.CubaTimer.extend(CubaTimer.java:43)
	at com.haulmont.cuba.web.AppUI.addTimer(AppUI.java:710)
	at com.haulmont.cuba.web.gui.components.WebTimer.attachTimerToUi(WebTimer.java:137)
	at com.haulmont.cuba.web.gui.components.WebTimer$1.attach(WebTimer.java:128)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:496)
	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:273)
	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:237)
	at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1041)
	at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:646)
	at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:670)
	at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:571)
	at com.vaadin.ui.AbstractComponentContainer.addComponent(AbstractComponentContainer.java:178)
	at com.vaadin.ui.CssLayout.addComponent(CssLayout.java:121)
	at com.haulmont.cuba.web.sys.WebScreens.removeThisTabWindow(WebScreens.java:689)
	at com.haulmont.cuba.web.sys.WebScreens.remove(WebScreens.java:631)
	at com.haulmont.cuba.gui.screen.Screen.close(Screen.java:340)
	at com.joker.jokerapp.web.main.OrderScreen.onSendAndCloseBtnClick(OrderScreen.java:1369)
	at com.haulmont.bali.events.EventHub.publish(EventHub.java:170)
	at com.haulmont.cuba.web.gui.components.WebAbstractComponent.publish(WebAbstractComponent.java:92)
	at com.haulmont.cuba.web.gui.components.WebButton.buttonClicked(WebButton.java:65)
	at com.haulmont.cuba.web.widgets.CubaButton.fireClick(CubaButton.java:76)
	at com.vaadin.ui.Button$1.click(Button.java:57)

It seems something related to Timer, in fact if I remove the timer from the caller screen the error disappear. It start to give me this error few days ago, making apparently no changes to the code.

Hi,

Could you please prepare a small example where we can reproduce the issue? Without technical details (such as framework version) and working example it is nearly impossible to say what is going on.

It’s a little bit hard to me to make a working example but I will try, of course. The versions are the last for both, Framework 7.0.6 and Studio 10.0

Ok, I’ve removed all the unnecessary code from the two classes

This is the caller screen (MainScreen.java):

package com.joker.jokerapp.web.main;

import com.haulmont.cuba.gui.*;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.model.CollectionContainer;
import com.haulmont.cuba.gui.model.DataContext;
import com.haulmont.cuba.gui.screen.*;
import com.joker.jokerapp.entity.TableItem;

import javax.inject.Inject;
import javax.inject.Named;
import java.time.Instant;
import java.util.Date;

@UiController("jokerapp_MainScreen")
@UiDescriptor("main-screen.xml")
@LoadDataBeforeShow
public class MainScreen extends Screen {

    @Inject
    private ScreenBuilders screenBuilders;
    @Named("currentTimeField")
    private TimeField currentTimeField;

    @Subscribe
    protected void onAfterShow(AfterShowEvent event) {
        currentTimeField.setValue(Date.from(Instant.now()));

        getScreenData().loadAll();

        OrderScreen orderScreen = screenBuilders.screen(this)
                .withScreenClass(OrderScreen.class)
                .withAfterCloseListener(orderScreenAfterScreenCloseEvent -> {
                    if (orderScreenAfterScreenCloseEvent.getCloseAction().equals(WINDOW_COMMIT_AND_CLOSE_ACTION)) {

                    }
                })
                .build();
        orderScreen.show();
    }

    public void onMainScreenTimerClick(Timer source) {
    }
}

And this is the called (OrderScreen.java):

package com.joker.jokerapp.web.main;

import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.gui.ScreenBuilders;
import com.haulmont.cuba.gui.UiComponents;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.components.Button;
import com.haulmont.cuba.gui.components.GridLayout;
import com.haulmont.cuba.gui.components.TextField;
import com.haulmont.cuba.gui.model.*;
import com.haulmont.cuba.gui.screen.Screen;
import com.haulmont.cuba.gui.screen.Subscribe;
import com.haulmont.cuba.gui.screen.UiController;
import com.haulmont.cuba.gui.screen.UiDescriptor;
import com.joker.jokerapp.entity.*;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.*;

@UiController("jokerapp_OrderScreen")
@UiDescriptor("order-screen.xml")
public class OrderScreen extends Screen {

    @Subscribe("closeBtn")
    public void onCloseBtnClick(Button.ClickEvent event) {
        close(WINDOW_COMMIT_AND_CLOSE_ACTION);
    }
}

Sorry, I cannot reproduce the problem. Seems like I’m missing something. Is your MainScreen is opened as root level screen or not?

Could you just create a sample project and attach it here?

TimerIssueExample.rar (10.9 MB)

MainScreen is opened as root level screen, yes…

Thanks, this is very useful and I’ve managed to reproduce the problem. We will investigate it and try to fix.

By the way, why do you use 7.1-SNAPSHOT version of the platform? It is not released yet and in active development right now.

Yes ok, so far I didn’t care about the stable or not stable releases…next time I will update only to stable ones…