From 9fa9c7424b5ff2a587d8e39db5a6f353c61f9719 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Fri, 7 Aug 2026 12:52:11 +0200 Subject: [PATCH] Remove unused WeakRefList WeakRefList holds weak references to injected objects so that the list does not keep them alive. It arrived with bug 295880 and its only client was ContextInjector, which stopped using it in 2b16cac21e "Bug 304586 - Injected methods only react to changes to method arguments" on 2010-03-03. Nothing has referenced it since. The package is exported with x-friends naming org.eclipse.e4.core.contexts and org.eclipse.e4.ui.workbench. Neither imports the class, so the export needs no change and no API is affected. --- .../e4/core/internal/di/WeakRefList.java | 80 ------------------- 1 file changed, 80 deletions(-) delete mode 100644 runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/WeakRefList.java diff --git a/runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/WeakRefList.java b/runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/WeakRefList.java deleted file mode 100644 index 1ba8c893728..00000000000 --- a/runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/WeakRefList.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.e4.core.internal.di; - -import java.lang.ref.WeakReference; -import java.util.*; - -/** - * A list that holds weak references to the objects. - */ -public class WeakRefList { - - private final List> userObjects; - - public WeakRefList(int initialSize) { - userObjects = new ArrayList<>(initialSize); - } - - public Object[] getSafeCopy() { - Object[] result; - int pos = 0; - synchronized (userObjects) { - result = new Object[userObjects.size()]; - for (Iterator> i = userObjects.iterator(); i.hasNext();) { - WeakReference ref = i.next(); - Object userObject = ref.get(); - if (userObject == null) { - // user object got GCed, clean up refs for future - i.remove(); - continue; - } - result[pos] = userObject; - pos++; - } - } - if (pos == result.length) { - return result; - } - // reallocate the array - Object[] tmp = new Object[pos]; - System.arraycopy(result, 0, tmp, 0, pos); - return tmp; - } - - public void add(Object object) { - WeakReference ref = new WeakReference<>(object); - synchronized (userObjects) { - userObjects.add(ref); - } - } - - public boolean remove(Object object) { - synchronized (userObjects) { - for (Iterator> i = userObjects.iterator(); i.hasNext();) { - WeakReference ref = i.next(); - Object userObject = ref.get(); - if (userObject == null) { - i.remove(); - continue; - } - if (userObject == object) { // use pointer comparison - i.remove(); - return true; - } - } - return false; - } - } -}