IJPL-149423 [Kotlin] test problem p2282218: com.intellij.testFramework.TestLoggerFactory$TestLoggerAssertionError: Memory leak detected: 'com.intellij.ui.BalloonImpl@REDACTED-HASH' (class com.intellij.ui.BalloonImpl) was registered in Disposer as a child of 'ROOT_DISPOSABLE' (class com.intellij.openapi.util.Disposer$2) but wasn't disposed.

GitOrigin-RevId: f6e4aff0981f7fa5b417d69b7700e551d527777f
This commit is contained in:
Alexander Lobas
2024-05-18 00:11:20 +02:00
committed by intellij-monorepo-bot
parent c1ab164213
commit b3c56dc86c
2 changed files with 12 additions and 26 deletions

View File

@@ -18,12 +18,10 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public final class BalloonPopupBuilderImpl implements BalloonBuilder {
private final @Nullable Map<Disposable, List<Balloon>> myStorage;
private @Nullable Disposable myAnchor;
private final JComponent myContent;
@@ -62,8 +60,15 @@ public final class BalloonPopupBuilderImpl implements BalloonBuilder {
private int myCornerRadius = -1;
private boolean myPointerShiftedToStart;
/**
* @deprecated use {@link BalloonPopupBuilderImpl#BalloonPopupBuilderImpl(JComponent)}
*/
@Deprecated
public BalloonPopupBuilderImpl(@Nullable Map<Disposable, List<Balloon>> storage, final @NotNull JComponent content) {
myStorage = storage;
this(content);
}
public BalloonPopupBuilderImpl(@NotNull JComponent content) {
myContent = content;
if (ClientProperty.isTrue(myContent, BalloonImpl.FORCED_NO_SHADOW)) {
myShadow = false;
@@ -261,22 +266,8 @@ public final class BalloonPopupBuilderImpl implements BalloonBuilder {
result.setCornerRadius(myCornerRadius);
result.setPointerShiftedToStart(myPointerShiftedToStart);
if (myStorage != null && myAnchor != null) {
List<Balloon> balloons = myStorage.get(myAnchor);
if (balloons == null) {
myStorage.put(myAnchor, balloons = new ArrayList<>());
Disposer.register(myAnchor, () -> {
List<Balloon> toDispose = myStorage.remove(myAnchor);
if (toDispose != null) {
for (Balloon balloon : toDispose) {
if (!balloon.isDisposed()) {
Disposer.dispose(balloon);
}
}
}
});
}
balloons.add(result);
if (myAnchor != null) {
Disposer.register(myAnchor, result);
result.addListener(new JBPopupListener() {
@Override
public void onClosed(@NotNull LightweightWindowEvent event) {

View File

@@ -5,7 +5,6 @@ import com.intellij.CommonBundle;
import com.intellij.ide.IdeEventQueue;
import com.intellij.ide.IdeTooltipManager;
import com.intellij.internal.inspector.UiInspectorUtil;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.impl.ActionMenu;
import com.intellij.openapi.actionSystem.impl.ActionPresentationDecorator;
@@ -56,8 +55,6 @@ import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.function.Function;
public class PopupFactoryImpl extends JBPopupFactory {
@@ -79,8 +76,6 @@ public class PopupFactoryImpl extends JBPopupFactory {
private static final Logger LOG = Logger.getInstance(PopupFactoryImpl.class);
private final Map<Disposable, List<Balloon>> myStorage = new WeakHashMap<>();
@Override
public @NotNull <T> IPopupChooserBuilder<T> createPopupChooserBuilder(@NotNull List<? extends T> list) {
LOG.assertTrue(list.isEmpty() || !(list.get(0) instanceof PsiElement) || ApplicationManager.getApplication().isUnitTestMode(),
@@ -642,12 +637,12 @@ public class PopupFactoryImpl extends JBPopupFactory {
@Override
public @NotNull BalloonBuilder createBalloonBuilder(@NotNull JComponent content) {
return new BalloonPopupBuilderImpl(myStorage, content);
return new BalloonPopupBuilderImpl(content);
}
@Override
public @NotNull BalloonBuilder createDialogBalloonBuilder(@NotNull JComponent content, @PopupTitle @Nullable String title) {
final BalloonPopupBuilderImpl builder = new BalloonPopupBuilderImpl(myStorage, content);
final BalloonPopupBuilderImpl builder = new BalloonPopupBuilderImpl(content);
return fillDialogBalloonBuilder(builder, title);
}