From 30f2890bafbc3604835648f0117d608011c30b8f Mon Sep 17 00:00:00 2001 From: Aydar Mukhametzyanov Date: Wed, 20 Nov 2024 13:30:58 +0100 Subject: [PATCH] IJPL-171343 IdeStatusBarImpl has a leak of a widget component GitOrigin-RevId: f9c0799e71ab982a65b13f8fb27a774942d64b85 --- .../openapi/wm/impl/status/IdeStatusBarImpl.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.kt index 39d4c084b23f..27c93a44fddf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.kt @@ -99,7 +99,7 @@ open class IdeStatusBarImpl @ApiStatus.Internal constructor( private val widgetMap = LinkedHashMap() private var leftPanel: JPanel? = null - private val rightPanelLayout = GridBagLayout() + private var rightPanelLayout = GridBagLayout() private val rightPanel: JPanel private val centerPanel: JPanel @@ -747,6 +747,7 @@ open class IdeStatusBarImpl @ApiStatus.Internal constructor( val targetPanel = getTargetPanel(bean.position) targetPanel.remove(bean.component) + recreateLayoutIfIsEmptyRightPanel(targetPanel) targetPanel.revalidate() Disposer.dispose(bean.widget) fireWidgetRemoved(id) @@ -755,6 +756,17 @@ open class IdeStatusBarImpl @ApiStatus.Internal constructor( } } + private fun recreateLayoutIfIsEmptyRightPanel(panel: JPanel) { + if (panel !== rightPanel && panel.components.none { it.isVisible }) return + + // Workaround of a bug in AWT: + // GridBagLayout.componentAdjusting is not set to NULL after removing the last visible child component. + // That leads to a leak of the StatusBarWidget component, and that leads to a situation when the plugin can't be properly unloaded. + rightPanelLayout = GridBagLayout() + panel.layout = rightPanelLayout + sortRightWidgets() + } + override fun updateWidget(id: String) { EdtInvocationManager.invokeLaterIfNeeded { val widgetComponent = getWidgetComponent(id)