void (@NotNull Balloon balloon) { var oldBalloon = myBalloonRef.getAndSet(new WeakReference<>(balloon)); hideBalloon(oldBalloon); balloon.addListener(new JBPopupListener() { @Override public void onClosed(@NotNull LightweightWindowEvent event) { myBalloonRef.updateAndGet(prev -> SoftReference.dereference(prev) == balloon ? null : prev); } }); }