IJPL-171343 IdeStatusBarImpl has a leak of a widget component

GitOrigin-RevId: f9c0799e71ab982a65b13f8fb27a774942d64b85
This commit is contained in:
Aydar Mukhametzyanov
2024-11-20 14:29:26 +00:00
committed by intellij-monorepo-bot
parent f073bcc86d
commit 30f2890baf
@@ -99,7 +99,7 @@ open class IdeStatusBarImpl @ApiStatus.Internal constructor(
private val widgetMap = LinkedHashMap<String, WidgetBean>()
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)