Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

package org.eclipse.ui.statushandlers;

import java.util.List;
import java.util.Vector;
import java.util.Collections;
import java.util.Set;
import java.util.WeakHashMap;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IStatus;
Expand Down Expand Up @@ -116,7 +117,9 @@ public class StatusManager {

private volatile AbstractStatusHandler statusHandler;

private final List<IStatus> loggedStatuses = new Vector<>();
// Weakly held so that a status which never reaches the log listener cannot accumulate.
private final Set<IStatus> loggedStatuses = Collections
.newSetFromMap(Collections.synchronizedMap(new WeakHashMap<IStatus, Boolean>()));

private final ListenerList<INotificationListener> listeners = new ListenerList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
SupportTrayTest.class,
WorkbenchStatusDialogManagerImplTest.class,
WizardsStatusHandlingTestCase.class,
StatusManagerTest.class,
})
public class StatusHandlingTestSuite {
//
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2026 vogella GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Lars Vogel <Lars.Vogel@vogella.com> - initial API and implementation
******************************************************************************/

package org.eclipse.ui.tests.statushandlers;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.statushandlers.StatusManager;
import org.eclipse.ui.tests.leaks.LeakTests;
import org.junit.jupiter.api.Test;

/**
* Tests that the {@link StatusManager} singleton does not retain the statuses it
* is told about.
*/
public class StatusManagerTest {

/**
* The entry is only dropped again once the very same instance comes back
* through the log listener, which does not happen for every caller.
*/
@Test
public void testStatusNeverReachingTheLogListenerIsNotRetained() throws Exception {
ReferenceQueue<IStatus> queue = new ReferenceQueue<>();
IStatus status = new Status(IStatus.ERROR, "org.eclipse.ui.tests", "never logged"); //$NON-NLS-1$ //$NON-NLS-2$
WeakReference<IStatus> ref = new WeakReference<>(status, queue);

StatusManager.getManager().addLoggedStatus(status);
status = null; // drop the only strong reference

LeakTests.checkRef(queue, ref);
}
}
Loading