Rich Search on side menu failinf randomly

Hi

Got the following error randomly in production when using rich search. Sadly I’m unable to reproduce it in development environment, neither in a small project.

11:13:11.563 ERROR c.h.c.w.g.c.WebSuggestionField - Error in async search thread
com.google.common.util.concurrent.UncheckedExecutionException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.search_SideMenu' defined in com.haulmont.addon.search.web.configuration.MenuProvider: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.haulmont.cuba.gui.components.mainwindow.SideMenu]: Factory method 'sideMenu' threw exception; nested exception is java.lang.NullPointerException
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2207)
at com.google.common.cache.LocalCache.get(LocalCache.java:3953)
at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4790)
at com.haulmont.addon.search.strategy.SideMenuSearchStrategy.load(SideMenuSearchStrategy.java:45)
at com.haulmont.addon.search.presenter.impl.SearchPresenterImpl.load(SearchPresenterImpl.java:74)
at com.haulmont.addon.search.presenter.impl.SearchPresenterImpl.lambda$load$0(SearchPresenterImpl.java:67)
at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:267)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at com.haulmont.addon.search.presenter.impl.SearchPresenterImpl.load(SearchPresenterImpl.java:70)
at com.haulmont.addon.search.web.gui.components.WebRichSearch.search(WebRichSearch.java:119)
at com.haulmont.cuba.web.gui.components.WebSuggestionField.asyncSearch(WebSuggestionField.java:224)
at com.haulmont.cuba.web.gui.components.WebSuggestionField$1.run(WebSuggestionField.java:181)
at com.haulmont.cuba.web.gui.components.WebSuggestionField$1.run(WebSuggestionField.java:174)
at com.haulmont.cuba.web.gui.executors.impl.WebBackgroundWorker$WebTaskExecutor.call(WebBackgroundWorker.java:205)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.haulmont.cuba.web.gui.executors.impl.WebBackgroundWorker$WebTaskExecutor.lambda$startExecution$1(WebBackgroundWorker.java:376)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.search_SideMenu' defined in com.haulmont.addon.search.web.configuration.MenuProvider: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.haulmont.cuba.gui.components.mainwindow.SideMenu]: Factory method 'sideMenu' threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1177)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1072)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:331)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:192)
at com.sun.proxy.$Proxy401.getMenuItems(Unknown Source)
at com.haulmont.addon.search.strategy.loader.SideMenuDataLoader.<init>(SideMenuDataLoader.java:27)
at com.haulmont.addon.search.strategy.SideMenuSearchStrategy.lambda$load$0(SideMenuSearchStrategy.java:46)
at com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4793)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3542)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2323)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2286)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201)
... 24 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.haulmont.cuba.gui.components.mainwindow.SideMenu]: Factory method 'sideMenu' threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 40 common frames omitted
Caused by: java.lang.NullPointerException: null
at com.haulmont.addon.search.web.configuration.MenuProvider.sideMenu(MenuProvider.java:28)
at com.haulmont.addon.search.web.configuration.MenuProvider$$EnhancerBySpringCGLIB$$e2bcf0e4.CGLIB$sideMenu$0(<generated>)
at com.haulmont.addon.search.web.configuration.MenuProvider$$EnhancerBySpringCGLIB$$e2bcf0e4$$FastClassBySpringCGLIB$$c0a4c06f.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
at com.haulmont.addon.search.web.configuration.MenuProvider$$EnhancerBySpringCGLIB$$e2bcf0e4.sideMenu(<generated>)
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 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 41 common frames omitted
11:13:11.846 ERROR c.h.c.w.g.c.WebSuggestionField - Error in async search thread
com.google.common.util.concurrent.UncheckedExecutionException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.search_SideMenu' defined in com.haulmont.addon.search.web.configuration.MenuProvider: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.haulmont.cuba.gui.components.mainwindow.SideMenu]: Factory method 'sideMenu' threw exception; nested exception is java.lang.NullPointerException
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2207)
at com.google.common.cache.LocalCache.get(LocalCache.java:3953)
at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4790)
at com.haulmont.addon.search.strategy.SideMenuSearchStrategy.load(SideMenuSearchStrategy.java:45)
at com.haulmont.addon.search.presenter.impl.SearchPresenterImpl.load(SearchPresenterImpl.java:74)
at com.haulmont.addon.search.presenter.impl.SearchPresenterImpl.lambda$load$0(SearchPresenterImpl.java:67)
at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:267)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at com.haulmont.addon.search.presenter.impl.SearchPresenterImpl.load(SearchPresenterImpl.java:70)
at com.haulmont.addon.search.web.gui.components.WebRichSearch.search(WebRichSearch.java:119)
at com.haulmont.cuba.web.gui.components.WebSuggestionField.asyncSearch(WebSuggestionField.java:224)
at com.haulmont.cuba.web.gui.components.WebSuggestionField$1.run(WebSuggestionField.java:181)
at com.haulmont.cuba.web.gui.components.WebSuggestionField$1.run(WebSuggestionField.java:174)
at com.haulmont.cuba.web.gui.executors.impl.WebBackgroundWorker$WebTaskExecutor.call(WebBackgroundWorker.java:205)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.haulmont.cuba.web.gui.executors.impl.WebBackgroundWorker$WebTaskExecutor.lambda$startExecution$1(WebBackgroundWorker.java:376)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.search_SideMenu' defined in com.haulmont.addon.search.web.configuration.MenuProvider: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.haulmont.cuba.gui.components.mainwindow.SideMenu]: Factory method 'sideMenu' threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1177)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1072)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:331)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:192)
at com.sun.proxy.$Proxy401.getMenuItems(Unknown Source)
at com.haulmont.addon.search.strategy.loader.SideMenuDataLoader.<init>(SideMenuDataLoader.java:27)
at com.haulmont.addon.search.strategy.SideMenuSearchStrategy.lambda$load$0(SideMenuSearchStrategy.java:46)
at com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4793)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3542)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2323)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2286)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201)
... 24 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.haulmont.cuba.gui.components.mainwindow.SideMenu]: Factory method 'sideMenu' threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 40 common frames omitted
Caused by: java.lang.NullPointerException: null
at com.haulmont.addon.search.web.configuration.MenuProvider.sideMenu(MenuProvider.java:28)
at com.haulmont.addon.search.web.configuration.MenuProvider$$EnhancerBySpringCGLIB$$e2bcf0e4.CGLIB$sideMenu$0(<generated>)
at com.haulmont.addon.search.web.configuration.MenuProvider$$EnhancerBySpringCGLIB$$e2bcf0e4$$FastClassBySpringCGLIB$$c0a4c06f.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
at com.haulmont.addon.search.web.configuration.MenuProvider$$EnhancerBySpringCGLIB$$e2bcf0e4.sideMenu(<generated>)
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 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 41 common frames omitted

In the meantime I have extended SearchPresenterImpl.load the following way to increase robustness.

    /**
     * in case of exception, catch it, log error and return empty stream
     */
    @Override
    protected Stream<SearchEntry> load(SearchContext context, SearchStrategy searchStrategy, String query) {
        try {
            return super.load(context, searchStrategy, query);
        } catch (Exception e) {
            log.error("Error executing search strategy : " + searchStrategy.name(), e);
            return Stream.empty();
        }
    }

But I do not understand why sometimes MenuProvider.sideMenu() (below) raises a NPE.

I upgraded from 6.10.13 to 6.10.15, maybe that’s the culprit.

    @Bean("search_SideMenu")
    @Scope(value = "prototype", proxyMode = ScopedProxyMode.INTERFACES)
    public SideMenu sideMenu() {
        return ((SideMenu) AppUI.getCurrent().getTopLevelWindow().getComponentNN("sideMenu"));
    }

Regards
Michael

Hi @michael.renaud,

Please provide your main screen layout

Regards,
Evgeny

Here you are @evgeny.zaharchenko

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="mainMsg://application.caption"
        class="com.busy.app.web.screens.ExtAppMainWindow"
        xmlns:ext="http://schemas.haulmont.com/cuba/window-ext.xsd"
        xmlns:main="http://schemas.haulmont.com/cuba/mainwindow.xsd"
        xmlns:search="http://schemas.haulmont.com/cuba/search.xsd"
>
    <timers>
        <timer id="updateCountersTimer"
               autostart="true"
               delay="3000"
               onTimer="updateCounters"
               repeating="true"/>
    </timers>
    <actions>
        <action id="openMessagesAction"
                caption=""
                icon="font-icon:ENVELOPE"
                invoke="openMessages"/>
        <action id="gotoHome"
                caption=""
                icon="font-icon:HOME"
                invoke="gotoHome"/>
        <action id="noteAction"
                caption=""
                icon="font-icon:FILE"
                invoke="openNotes"/>
        <action id="userSettingsAction"
                caption=""
                icon="font-icon:USER"
                invoke="openUserSettings"/>
    </actions>
    <layout responsive="true"
            stylename="sidemenu-responsive sidemenu-drawer">
        <hbox id="horizontalWrap"
              height="100%"
              stylename="c-sidemenu-layout"
              expand="workArea"
              width="100%">
            <cssLayout id="sideMenuPanel"
                       height="100%"
                       stylename="c-sidemenu-panel">
                <button id="mobileMenuButton"
                        caption="mainMsg://app.menu"
                        icon="icons/mobile-menu.png"
                        stylename="primary c-sidemenu-toggle"/>
                <hbox id="mobileButtonsBox"
                      stylename="c-sidemenu-mobile-buttons">
                    <main:newWindowButton id="mobileNewWindowButton"
                                          description="mainMsg://newWindowBtnDescription"
                                          icon="app/images/new-window.png"/>
                    <main:logoutButton id="mobileLogoutButton"
                                       description="mainMsg://logoutBtnDescription"
                                       icon="app/images/exit.png"/>
                </hbox>
                <hbox id="appTitleBox"
                      stylename="c-sidemenu-title"
                      width="100%">
                    <hbox width="30%"/>
                    <hbox align="MIDDLE_CENTER">
                        <label id="appTitleLabel"
                               value="mainMsg://application.logoLabel"
                               stylename="small"
                        />
                    </hbox>
                    <hbox align="MIDDLE_RIGHT">
                        <search:richSearch id="search"
                                           align="MIDDLE_LEFT"
                                           ext:index="3"
                                           stylename="small"
                                           inputPrompt="msg://search"
                                           suggestionsLimit="200">
                            <search:strategyBean name="search_SaleTargetSearchStrategy"/>
                            <search:strategyBean name="search_SaleOfferSearchStrategy"/>
                            <search:strategyBean name="search_CustomerOrderSearchStrategy"/>
                            <search:strategyBean name="search_CustomerInvoiceSearchStrategy"/>
                            <search:strategyBean name="search_ProductSearchStrategy"/>
                            <search:strategyBean name="search_UsersSearchStrategy"/>
                            <search:strategyBean name="search_RoleSearchStrategy"/>
                            <search:strategyBean name="search_SideMenuSearchStrategy"/>
                            <search:strategyBean name="search_FtsSearchStrategy"/>
                        </search:richSearch>
                        <button id="msgBtn"
                                action="openMessagesAction"
                                description="Ouvrir la messagerie"
                                stylename="borderless-colored"
                        />
                        <button id="homeBtn"
                                action="gotoHome"
                                description="Afficher l'écran d'accueil"
                                stylename="borderless"
                        />
                        <button id="userSettingBtn"
                                action="userSettingsAction"
                                description="Ouvrir vos préférences"
                                stylename="borderless"
                        />
                        <button id="noteBtn"
                                action="noteAction"
                                stylename="borderless"/>
                        <label width="30px"/>
                        <label width="60px"/>
                    </hbox>
                </hbox>
                <cssLayout id="sideMenuWrap"
                           stylename="c-sidemenu-wrap">
                    <vbox spacing="true">
                        <main:userIndicator id="userIndicator"
                                            align="MIDDLE_LEFT"
                                            width="100%"/>
                        <main:timeZoneIndicator id="timeZoneIndicator"
                                                width="100%"/>
                    </vbox>
                    <main:sideMenu id="sideMenu"
                                   showSingleExpandedMenu="true"
                                   sidePanel="sideMenuPanel"
                                   sidePanelToggleButton="mobileMenuButton"/>
                </cssLayout>
            </cssLayout>
            <main:workArea id="workArea"
                           height="100%">
                <main:initialLayout margin="true"
                                    spacing="true">
                    <label id="welcomeLabel"
                           align="MIDDLE_CENTER"
                           stylename="bold h4"/>
                </main:initialLayout>
            </main:workArea>
        </hbox>
    </layout>
</window>

And the controller

package com.busy.app.web.screens;

import com.busy.app.conf.BusyTenantConfig;
import com.busy.app.global.log.LogMonitorEvent;
import com.busy.app.service.sys.message.MessageService;
import com.busy.app.web.components.actions.busystd.BusyStdFrame;
import com.busy.app.web.util.WindowUtils;
import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.components.actions.BaseAction;
import com.haulmont.cuba.gui.components.mainwindow.SideMenu;
import com.haulmont.cuba.gui.components.mainwindow.UserIndicator;
import com.haulmont.cuba.gui.icons.Icons;
import com.haulmont.cuba.web.WebConfig;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.event.EventListener;

import javax.inject.Inject;
import java.util.Map;

public class ExtAppMainWindow extends AbstractMainWindow implements BusyStdFrame {

    @Inject
    SideMenu sideMenu;

    @Inject
    MessageService messageService;

    @Inject
    Timer updateCountersTimer;

    @Inject
    WebConfig webConfig;

    @Inject
    BusyTenantConfig tenantConfig;

    @Inject
    UserIndicator userIndicator;

    @Inject
    Label welcomeLabel;

    @Inject
    Icons icons;

    @Inject
    HBoxLayout appTitleBox;

    @Inject
    HBoxLayout mobileButtonsBox;

    @Inject
    Label appTitleLabel;

    @Inject
    Button mobileMenuButton;

    @Inject
    Button msgBtn;

    String hasMessageStyle = "has-message";

    String noMessageStyle = "white";

    @Override
    public void init(Map<String, Object> params) {
        super.init(params);
//        initLayoutAnalyzerContextMenu(logoImage);
//        initLogoImage(logoImage);
//        initFtsField(ftsField);
        //userIndicator.setUserNameFormatter(InstanceUtils::getInstanceName);
        appTitleLabel.setValue(/*SecUtils.currentUser().getInstanceName() + "@" + */
                tenantConfig.getTenantName().toUpperCase()
                /*+ "[" + tenantConfig.getTenantCode() + "]"*/);
        //sideMenu.requestFocus();
        //sideMenu.getSidePanel().addStyleName(HaloTheme.SIDEMENU_PANEL_OPEN);
        initPresentation();
        initLayoutAnalyzerContextMenu(mobileMenuButton);
        //initLogoImage(logoImage);
        //initFtsField(ftsField);
        initUpdateCounterTimerDelay();
        initDashboardMenuItem();
        initMessagesMenuItem();
        sideMenu.setSelectOnClick(true);
        // icons
        SideMenu.MenuItem reports = sideMenu.getMenuItem("reports");
        if (reports != null) reports.setIcon(icons.get("BRIEFCASE"));
        SideMenu.MenuItem admin = sideMenu.getMenuItem("administration");
        if (admin != null) admin.setIcon(icons.get("GEAR"));
        SideMenu.MenuItem help = sideMenu.getMenuItem("help");
        if (help != null) help.setIcon(icons.get("LIFE_BUOY"));

    }

    protected void initPresentation() {
    }

    protected void initLogoImage(Image logoImage) {
        String logoImagePath = messages.getMainMessage("application.logoImage");
        if (StringUtils.isNotBlank(logoImagePath) && !"application.logoImage".equals(logoImagePath)) {
            logoImage.setSource(ThemeResource.class).setPath(logoImagePath);
        }
    }

    @EventListener
    public void handle(LogMonitorEvent event) {
        showNotification(event.getRawString(), NotificationType.TRAY);
    }

    public void validateRights() {
//        List<RightsValidationError> errors = new ArrayList<>();
//        errors.addAll(validateScreenPermissions());
//        if (errors.size() > 0) {
//            eventBus.publish(new RightsSetupValidationErrorEvent(this, errors));
//        }
    }

    public void openMessages() {
        openWindow("user-inbox", WindowManager.OpenType.NEW_TAB);
    }

    private void initUpdateCounterTimerDelay() {
        int period = webConfig.getAppFoldersRefreshPeriodSec() * 1000;
        updateCountersTimer.setDelay(period);
    }

    private void initDashboardMenuItem() {
        //now a dedicated icon in title bar
        /*
        SideMenu.MenuItem menuItem = sideMenu.createMenuItem("dashboard");
        menuItem.setCaption(messages.getMessage(DashboardScreen.class, "caption"));
        menuItem.setIcon("font-icon:HOME");
        menuItem.setCommand(mi -> openWindow("dashboard-screen", WindowManager.OpenType.NEW_TAB));
        sideMenu.addMenuItem(menuItem, 0);
        */
    }

    private void initMessagesMenuItem() {
        //msgBtn = factory.createComponent(Button.class);
        Action openMessages = new BaseAction("openMessages")
                .withCaption("")
                .withIcon("font-icon:ENVELOPE")
                .withHandler(e -> openWindow("user-inbox", WindowManager.OpenType.NEW_TAB));
        msgBtn.setAction(openMessages);
        //msgBtn.addStyleName("borderless");
        //mobileButtonsBox.add(msgBtn, 0);

        SideMenu.MenuItem messagesMenuItem = sideMenu.createMenuItem("messages");
        messagesMenuItem.setCaption(messages.getMainMessage("user-inbox.messages"));
        messagesMenuItem.setIcon("font-icon:ENVELOPE");
        messagesMenuItem.setCommand(menuItem -> openWindow("user-inbox", WindowManager.OpenType.NEW_TAB));
        sideMenu.addMenuItem(messagesMenuItem, 0);

    }

    @Override
    public void ready() {
        try {
            super.ready();
        } catch (Throwable t) {
            getWindowManager().showExceptionDialog(t, "Erreur à l'ouverture", "Erreur lors de l'ouverture de l'écran d'accueil");
        }
        updateMessageCounter();
        validateRights();
    }

    public void updateCounters(Timer source) {
        updateMessageCounter();
    }

    int prevMessageCounter = -1;

    private void updateMessageCounter() {
        int count = getMessageCounter();
        if (count == prevMessageCounter)
            return;
        String title = "Messagerie";
        if (prevMessageCounter < 0) {
            // first update
            if (count == 1) {
                showTrayNotification(title, "Vous avez un message non lu");
            }
            else if (count > 1) {
                showTrayNotification(title, "Vous avez " + count + " messages non lus");
            }
        } else {
            // next update
            if (count - prevMessageCounter == 1) {
                showTrayNotification(title, "Vous avez un nouveau message");
            }
            if (count - prevMessageCounter > 1) {
                showTrayNotification(title, "Vous avez " + (count - prevMessageCounter) + " nouveaux messages");
            }
        }
        sideMenu.getMenuItemNN("messages").setBadgeText(count == 0 ? null : count + "");
        if (count > 0) {
            msgBtn.removeStyleName(noMessageStyle);
            msgBtn.addStyleName(hasMessageStyle);
            msgBtn.setCaption("(" + count + ")");
        } else {
            msgBtn.removeStyleName(hasMessageStyle);
            msgBtn.addStyleName(noMessageStyle);
            msgBtn.setCaption("");
        }
        prevMessageCounter = count;
    }

    private int getMessageCounter() {
        return messageService.countUnreadMessagesForCurrentUser();
    }

    public void openUserSettings() {
        Window win = openWindow("settings", WindowManager.OpenType.DIALOG);
        win.setCaption("Préférences");
    }


    public void openNotes() {
        //System.out.println(AppUI.getCurrent().getTopLevelWindow().getComponent("sideMenu"));
        //System.out.println("notes not yet implemented");
    }

    public void gotoHome() {
        openWindow("dashboard-screen", WindowUtils.NEW_TAB);
    }
}

Hi @michael.renaud,

Sorry but we couldn’t reproduce the problem. if the problem is still relevant please provide more info about your application, what is your server environment, do you use other add-ons in your project?

Regards,
Evgeny

Hi @evgeny.zaharchenko

Jelastic / app server Tomcat 8.5.23 / PostgreSql 9.6.6

2 cuba applications running over the same server, same one but with different configuration, 2 physical tenants with its own database.

Cuba 6.10.15

Add-ons:
dependencies {
appComponent(“com.haulmont.cuba:cuba-global:$cubaVersion”)
appComponent(“com.haulmont.reports:reports-global:$cubaVersion”)
appComponent(“com.haulmont.fts:fts-global:$cubaVersion”)
appComponent(“com.haulmont.charts:charts-global:$cubaVersion”)
appComponent(“it.nexbit.cuba.security.forgotpassword:nxsecfp-global:2.2.0”)
appComponent(“com.haulmont.addon.dnd:cuba-dnd-global:1.4.0”)
appComponent(“de.balvi.cuba.declarativecontrollers:declarativecontrollers-global:0.7.0”)
appComponent(“com.haulmont.addon.globalevents:cubaglevt-global:0.3.0”)
appComponent(“org.strangeway.responsive:sw-responsive-global:1.2.0”)
appComponent(“de.diedavids.cuba.entitysoftreference:entity-soft-reference-global:0.4.0”)
appComponent(“de.diedavids.cuba.runtimediagnose:runtime-diagnose-global:1.2.0”)
appComponent(“de.diedavids.cuba.attachable:attachable-global:0.5.1”)
appComponent(“com.haulmont.addon.admintools:cuba-at-global:1.2.1”)
appComponent(“com.haulmont.addon.search:search-global:1.3.0”)
}

I did check production logs, it is still appearing randomly, there is an interesting burst on 4th March:

15:54:00.744 ERROR [BackgroundTask-0-gilles] c.b.a.w.s.ExtSearchPresenterImpl - Error executing search strategy : searchStrategy.sideMenu
com.google.common.util.concurrent.UncheckedExecutionException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.search_SideMenu' defined in com.haulmont.addon.search.web.configuration.MenuProvider: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.haulmont.cuba.gui.components.mainwindow.SideMenu]: Factory method 'sideMenu' threw exception; nested exception is java.lang.NullPointerException

15:54:01.055 ERROR [BackgroundTask-1-gilles] c.b.a.w.s.ExtSearchPresenterImpl - Error executing search strategy : searchStrategy.sideMenu
com.google.common.util.concurrent.UncheckedExecutionException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.search_SideMenu' defined in com.haulmont.addon.search.web.configuration.MenuProvider: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.haulmont.cuba.gui.components.mainwindow.SideMenu]: Factory method 'sideMenu' threw exception; nested exception is java.lang.NullPointerException

15:54:01.396 ERROR [BackgroundTask-2-gilles] c.b.a.w.s.ExtSearchPresenterImpl - Error executing search strategy : searchStrategy.sideMenu
com.google.common.util.concurrent.UncheckedExecutionException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.search_SideMenu' defined in com.haulmont.addon.search.web.configuration.MenuProvider: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.haulmont.cuba.gui.components.mainwindow.SideMenu]: Factory method 'sideMenu' threw exception; nested exception is java.lang.NullPointerException

15:54:02.035 ERROR [BackgroundTask-3-gilles] c.b.a.w.s.ExtSearchPresenterImpl - Error executing search strategy : searchStrategy.sideMenu
com.google.common.util.concurrent.UncheckedExecutionException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.search_SideMenu' defined in com.haulmont.addon.search.web.configuration.MenuProvider: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.haulmont.cuba.gui.components.mainwindow.SideMenu]: Factory method 'sideMenu' threw exception; nested exception is java.lang.NullPointerException

No thorough analysis of mine but I have the feeling this is a synchronisation issue, knowing that search is executed by spawning a background thread.

Following code of MenuProvider.sideMenu fails sometimes:

 @Bean("search_SideMenu")
    @Scope(value = "prototype", proxyMode = ScopedProxyMode.INTERFACES)
    public SideMenu sideMenu() {
        return ((SideMenu) AppUI.getCurrent().getTopLevelWindow().getComponentNN("sideMenu"));
    }

Knowing that getComponentNN has a distinctive error message, either AppUI.getCurrent() returns null, or AppUI.getCurrent().getTopLevelWindow() returns null.

If this is the first, maybe that’s because Vaadin does not like when UI code is accessed out of UI thread, here we are in a background thread.

Is this is the second, knowing that topLevelWindow in AppUI can change through navigating (code below) there might be some sync needed.

/**
     * Initialize new TopLevelWindow and replace current
     *
     * @param topLevelWindowId target top level window id
     */
    public void navigateTo(String topLevelWindowId) {
        WebWindowManager wm = AppBeans.getPrototype(WebWindowManager.NAME);
        wm.setUi(AppUI.getCurrent());

        wm.createTopLevelWindow(windowConfig.getWindowInfo(topLevelWindowId));
    }

Michael