From 6bf7d1d0f69097b267d348d8d264e9b669f423a0 Mon Sep 17 00:00:00 2001 From: Maxim Monastirsky Date: Sun, 28 Aug 2016 20:55:55 +0300 Subject: ResourceMenuController: Better error handling This should stop crashes in framework::MenuBarManager::FillMenu as seen in crashreport. Unfortunately no idea how to reproduce those crashes other than corrupting the installation (e.g. removing files). Change-Id: Iaed8e888dd74c4c1bb5d6fd7996ecf80f4645b68 --- .../source/uielement/resourcemenucontroller.cxx | 30 ++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'framework/source') diff --git a/framework/source/uielement/resourcemenucontroller.cxx b/framework/source/uielement/resourcemenucontroller.cxx index 47c3f1ccd0f8..cfb2d839b565 100644 --- a/framework/source/uielement/resourcemenucontroller.cxx +++ b/framework/source/uielement/resourcemenucontroller.cxx @@ -159,14 +159,28 @@ void ResourceMenuController::updatePopupMenu() {} } - if ( !m_xMenuContainer.is() ) + if ( !m_xMenuContainer.is() && m_xConfigManager.is() ) { try { - if ( m_xConfigManager.is() && m_xConfigManager->hasSettings( m_aMenuURL ) ) - m_xMenuContainer.set( m_xConfigManager->getSettings( m_aMenuURL, false ) ); - else if ( m_xModuleConfigManager.is() && m_xModuleConfigManager->hasSettings( m_aMenuURL ) ) - m_xMenuContainer.set( m_xModuleConfigManager->getSettings( m_aMenuURL, false ) ); + m_xMenuContainer.set( m_xConfigManager->getSettings( m_aMenuURL, false ) ); + } + catch ( const css::container::NoSuchElementException& ) + { + // Not an error - element may exist only in the module. + } + catch ( const css::lang::IllegalArgumentException& ) + { + SAL_WARN( "fwk.uielement", "The given URL is not valid: " << m_aMenuURL ); + return; + } + } + + if ( !m_xMenuContainer.is() && m_xModuleConfigManager.is() ) + { + try + { + m_xMenuContainer.set( m_xModuleConfigManager->getSettings( m_aMenuURL, false ) ); } catch ( const css::container::NoSuchElementException& ) { @@ -180,6 +194,9 @@ void ResourceMenuController::updatePopupMenu() } } + if ( !m_xMenuContainer.is() ) + return; + // Clear previous content. if ( m_xMenuBarManager.is() ) { @@ -245,9 +262,6 @@ void ResourceMenuController::addVerbs( const css::uno::Sequence< css::embed::Ver void ResourceMenuController::fillToolbarData() { - if ( !m_xMenuContainer.is() ) - return; - VCLXMenu* pAwtMenu = VCLXMenu::GetImplementation( m_xPopupMenu ); Menu* pVCLMenu = pAwtMenu->GetMenu(); -- cgit