From a1a9eaf5879c77a3aa029ac318a826cceadb59ff Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sun, 19 Jun 2022 10:59:46 +0200 Subject: [PATCH] Apply new JDT clean-up "Convert while loops to enhanced for loops" ... without "Only if loop variable used" option being activated. And manually remove now unused imports, which the clean-up does not yet detect (a JDT issue is already created). Don't apply clean-up to embedded OSGi and Felix sources. --- .../equinox/internal/app/AppCommands.java | 4 +-- .../ds/tests/tb25/PolicyOptionComp.java | 4 +-- .../ds/tests/tb25/ServicePropertiesComp.java | 4 +-- .../equinox/ds/tests/BundleInstaller.java | 9 +++-- .../eclipse/equinox/ds/tests/tbc/DSTest.java | 4 +-- .../internal/ExtensionPointTracker.java | 11 +++--- .../http/registry/internal/FilterManager.java | 15 ++++---- .../internal/HttpRegistryManager.java | 6 ++-- .../registry/internal/ResourceManager.java | 9 ++--- .../registry/internal/ServletManager.java | 15 ++++---- .../http/servlet/testbase/BaseTest.java | 11 +++--- .../http/servlet/internal/Activator.java | 5 +-- .../registration/ServletRegistration.java | 6 ++-- .../region/hook/RegionResolverHook.java | 8 ++--- .../META-INF/MANIFEST.MF | 2 +- .../core/internal/registry/TableReader.java | 2 +- .../internal/useradmin/UserAdminStore.java | 36 +++++++++---------- .../osgi/internal/module/MappedList.java | 6 ++-- .../osgi/internal/module/ResolverImpl.java | 13 ++++--- .../resolver/BundleDescriptionImpl.java | 8 ++--- .../internal/resolver/StateDeltaImpl.java | 3 +- .../internal/resolver/StateHelperImpl.java | 5 ++- .../osgi/internal/resolver/StateImpl.java | 33 ++++++----------- .../osgi/internal/resolver/StateReader.java | 13 +++---- .../osgi/internal/resolver/StateWriter.java | 9 ++--- .../tests/appadmin/ApplicationAdminTest.java | 17 +++++---- .../debugoptions/DebugOptionsTestCase.java | 5 ++- .../osgi/tests/resource/BasicTest.java | 9 +++-- .../tests/resource/ResolverHookTests.java | 5 ++- .../services/resolver/OSGiCapabilityTest.java | 4 +-- .../osgi/container/ModuleDatabase.java | 5 +-- .../internal/container/ComputeNodeOrder.java | 4 +-- .../internal/debug/FrameworkDebugOptions.java | 14 ++++---- .../internal/framework/ContextFinder.java | 13 ++++--- .../framework/EquinoxConfiguration.java | 6 ++-- .../serviceregistry/ServiceRegistry.java | 22 ++++++------ .../signedcontent/SignedBundleHook.java | 5 ++- .../signedcontent/TrustEngineListener.java | 5 ++- .../src/org/eclipse/osgi/storage/Storage.java | 8 ++--- .../internal/reliablefile/ReliableFile.java | 19 +++++----- 40 files changed, 157 insertions(+), 225 deletions(-) diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppCommands.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppCommands.java index a43695903b1..f9468122a25 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppCommands.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppCommands.java @@ -113,9 +113,7 @@ private String getHelp(String commandName) { } addHeader(Messages.console_help_app_commands_header, sb); - Iterator> i = commandsHelp.entrySet().iterator(); - while (i.hasNext()) { - Entry entry = i.next(); + for (Entry entry : commandsHelp.entrySet()) { String command = entry.getKey(); String[] attributes = entry.getValue(); addCommand(command, attributes, sb); diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/PolicyOptionComp.java b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/PolicyOptionComp.java index 79f2110b9a9..72539b6dd61 100644 --- a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/PolicyOptionComp.java +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/PolicyOptionComp.java @@ -18,7 +18,6 @@ import java.util.Dictionary; import java.util.Enumeration; import java.util.Hashtable; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -72,8 +71,7 @@ public synchronized Dictionary getProperties() { } if (newProps != null) { - for (Iterator it = newProps.keySet().iterator(); it.hasNext();) { - Object key = it.next(); + for (Object key : newProps.keySet()) { result.put(key, newProps.get(key)); } } diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/ServicePropertiesComp.java b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/ServicePropertiesComp.java index 57b3db79fb7..94f0d1d28c8 100644 --- a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/ServicePropertiesComp.java +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/ServicePropertiesComp.java @@ -17,7 +17,6 @@ import java.util.Dictionary; import java.util.Enumeration; import java.util.Hashtable; -import java.util.Iterator; import java.util.Map; import org.eclipse.equinox.ds.tests.tbc.PropertiesProvider; @@ -77,8 +76,7 @@ public synchronized Dictionary getProperties() { } if (newProps != null) { - for (Iterator it = newProps.keySet().iterator(); it.hasNext();) { - Object key = it.next(); + for (Object key : newProps.keySet()) { result.put(key, newProps.get(key)); } } diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/BundleInstaller.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/BundleInstaller.java index 4f2d5ad3dee..c09635bb69c 100644 --- a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/BundleInstaller.java +++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/BundleInstaller.java @@ -17,7 +17,6 @@ import java.net.URL; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import org.eclipse.osgi.service.urlconversion.URLConverter; @@ -114,8 +113,8 @@ synchronized public void uninstallBundle(Bundle b) throws BundleException { if (bundles == null) return; if (bundles.containsValue(b)) { - for (Iterator it = bundles.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Map.Entry) it.next(); + for (Object element : bundles.entrySet()) { + Map.Entry entry = (Map.Entry) element; if (entry.getValue().equals(b)) { bundles.remove(entry.getKey()); break; @@ -129,8 +128,8 @@ synchronized public Bundle[] uninstallAllBundles() throws BundleException { if (bundles == null) return null; ArrayList result = new ArrayList(bundles.size()); - for (Iterator iter = bundles.values().iterator(); iter.hasNext();) { - Bundle bundle = (Bundle) iter.next(); + for (Object element : bundles.values()) { + Bundle bundle = (Bundle) element; try { bundle.uninstall(); } catch (IllegalStateException e) { diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java index 80126e2de3e..4044165d4bd 100644 --- a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java +++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java @@ -30,7 +30,6 @@ import java.util.Dictionary; import java.util.Enumeration; import java.util.Hashtable; -import java.util.Iterator; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -2925,8 +2924,7 @@ private static void assertEqualElements(String message, List list1, List list2) fail(message); } List tmp = new ArrayList(list2); - for (Iterator it = list1.iterator(); it.hasNext();) { - Object el = it.next(); + for (Object el : list1) { if (!tmp.contains(el)) { fail(message); } diff --git a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ExtensionPointTracker.java b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ExtensionPointTracker.java index 28fff5a8d03..2d08e4d9c1f 100644 --- a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ExtensionPointTracker.java +++ b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ExtensionPointTracker.java @@ -76,8 +76,8 @@ public void open() { } } if (extensions != null) { - for (int i = 0; i < extensions.length; ++i) { - listener.added(extensions[i]); + for (IExtension extension : extensions) { + listener.added(extension); } } } @@ -93,8 +93,8 @@ public void close() { extensions = this.getExtensions(); extensionCache.clear(); } - for (int i = 0; i < extensions.length; ++i) { - listener.removed(extensions[i]); + for (IExtension extension : extensions) { + listener.removed(extension); } } @@ -119,8 +119,7 @@ public synchronized IExtension[] getExtensions() { class RegistryChangeListener implements IRegistryChangeListener { public void registryChanged(IRegistryChangeEvent event) { IExtensionDelta[] deltas = event.getExtensionDeltas(namespace, simpleIdentifier); - for (int i = 0; i < deltas.length; ++i) { - IExtensionDelta delta = deltas[i]; + for (IExtensionDelta delta : deltas) { IExtension extension = delta.getExtension(); switch (delta.getKind()) { case IExtensionDelta.ADDED : diff --git a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/FilterManager.java b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/FilterManager.java index 4650dd51cd3..aad6773d593 100644 --- a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/FilterManager.java +++ b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/FilterManager.java @@ -70,8 +70,7 @@ public void stop() { public void added(IExtension extension) { IConfigurationElement[] elements = extension.getConfigurationElements(); - for (int i = 0; i < elements.length; i++) { - IConfigurationElement serviceSelectorElement = elements[i]; + for (IConfigurationElement serviceSelectorElement : elements) { if (!SERVICESELECTOR.equals(serviceSelectorElement.getName())) continue; @@ -105,8 +104,7 @@ public void added(IExtension extension) { break; } - for (int i = 0; i < elements.length; i++) { - IConfigurationElement filterElement = elements[i]; + for (IConfigurationElement filterElement : elements) { if (!FILTER.equals(filterElement.getName())) continue; @@ -117,9 +115,9 @@ public void added(IExtension extension) { Dictionary initparams = new Hashtable<>(); IConfigurationElement[] initParams = filterElement.getChildren(INIT_PARAM); - for (int j = 0; j < initParams.length; ++j) { - String paramName = initParams[j].getAttribute(PARAM_NAME); - String paramValue = initParams[j].getAttribute(PARAM_VALUE); + for (IConfigurationElement initParam : initParams) { + String paramName = initParam.getAttribute(PARAM_NAME); + String paramValue = initParam.getAttribute(PARAM_VALUE); initparams.put(paramName, paramValue); } @@ -142,8 +140,7 @@ public void added(IExtension extension) { public void removed(IExtension extension) { IConfigurationElement[] elements = extension.getConfigurationElements(); - for (int i = 0; i < elements.length; i++) { - IConfigurationElement filterElement = elements[i]; + for (IConfigurationElement filterElement : elements) { Filter filter = registered.remove(filterElement); if (filter != null) httpRegistryManager.removeFilterContribution(filter); diff --git a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpRegistryManager.java b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpRegistryManager.java index 784bc7bcbc2..6d54fcb3990 100644 --- a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpRegistryManager.java +++ b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpRegistryManager.java @@ -232,9 +232,9 @@ public Bundle getBundle(String symbolicName) { if (bundles == null) return null; //Return the first bundle that is not installed or uninstalled - for (int i = 0; i < bundles.length; i++) { - if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) { - return bundles[i]; + for (Bundle bundle : bundles) { + if ((bundle.getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) { + return bundle; } } return null; diff --git a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ResourceManager.java b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ResourceManager.java index b2977233600..ce6b23f76f8 100644 --- a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ResourceManager.java +++ b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ResourceManager.java @@ -64,8 +64,7 @@ public void stop() { public void added(IExtension extension) { IConfigurationElement[] elements = extension.getConfigurationElements(); - for (int i = 0; i < elements.length; i++) { - IConfigurationElement serviceSelectorElement = elements[i]; + for (IConfigurationElement serviceSelectorElement : elements) { if (!SERVICESELECTOR.equals(serviceSelectorElement.getName())) continue; @@ -99,8 +98,7 @@ public void added(IExtension extension) { break; } - for (int i = 0; i < elements.length; i++) { - IConfigurationElement resourceElement = elements[i]; + for (IConfigurationElement resourceElement : elements) { if (!RESOURCE.equals(resourceElement.getName())) continue; @@ -127,8 +125,7 @@ public void added(IExtension extension) { public void removed(IExtension extension) { IConfigurationElement[] elements = extension.getConfigurationElements(); - for (int i = 0; i < elements.length; i++) { - IConfigurationElement resourceElement = elements[i]; + for (IConfigurationElement resourceElement : elements) { if (registered.remove(resourceElement)) { String alias = resourceElement.getAttribute(ALIAS); httpRegistryManager.removeContribution(alias); diff --git a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ServletManager.java b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ServletManager.java index b2e357c166f..03e166ecef4 100644 --- a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ServletManager.java +++ b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ServletManager.java @@ -71,8 +71,7 @@ public void stop() { public void added(IExtension extension) { IConfigurationElement[] elements = extension.getConfigurationElements(); - for (int i = 0; i < elements.length; i++) { - IConfigurationElement serviceSelectorElement = elements[i]; + for (IConfigurationElement serviceSelectorElement : elements) { if (!SERVICESELECTOR.equals(serviceSelectorElement.getName())) continue; @@ -106,8 +105,7 @@ public void added(IExtension extension) { break; } - for (int i = 0; i < elements.length; i++) { - IConfigurationElement servletElement = elements[i]; + for (IConfigurationElement servletElement : elements) { if (!SERVLET.equals(servletElement.getName())) continue; @@ -118,9 +116,9 @@ public void added(IExtension extension) { Dictionary initparams = new Hashtable<>(); IConfigurationElement[] initParams = servletElement.getChildren(INIT_PARAM); - for (int j = 0; j < initParams.length; ++j) { - String paramName = initParams[j].getAttribute(PARAM_NAME); - String paramValue = initParams[j].getAttribute(PARAM_VALUE); + for (IConfigurationElement initParam : initParams) { + String paramName = initParam.getAttribute(PARAM_NAME); + String paramValue = initParam.getAttribute(PARAM_VALUE); initparams.put(paramName, paramValue); } @@ -143,8 +141,7 @@ public void added(IExtension extension) { public void removed(IExtension extension) { IConfigurationElement[] elements = extension.getConfigurationElements(); - for (int i = 0; i < elements.length; i++) { - IConfigurationElement servletElement = elements[i]; + for (IConfigurationElement servletElement : elements) { if (registered.remove(servletElement)) { String alias = servletElement.getAttribute(ALIAS); httpRegistryManager.removeContribution(alias); diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/BaseTest.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/BaseTest.java index 0f931834513..c9efcb12f93 100644 --- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/BaseTest.java +++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/BaseTest.java @@ -26,7 +26,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -229,14 +228,12 @@ else if (String[].class.isInstance(property)) { } else if (Collection.class.isInstance(property)) { List list = new ArrayList<>(); - for (@SuppressWarnings("rawtypes") - Iterator i = ((Collection)property).iterator(); i.hasNext();) { + for (Object o : ((Collection) property)) { - Object o = i.next(); - if (String.class.isInstance(o)) { - list.add((String)o); - } + if (String.class.isInstance(o)) { + list.add((String)o); } +} return list; } return Collections.emptyList(); diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java index 885e0c419ab..8907e3ed720 100644 --- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java +++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java @@ -325,15 +325,12 @@ private String assembleEndpoint(String protocol, String host, String port, Strin } private void processRegistrations() { - Iterator> iterator = - registrations.entrySet().iterator(); BundleContext currentContext = context; if (currentContext == null) { return; } - while (iterator.hasNext()) { - Entry entry = iterator.next(); + for (Entry entry : registrations.entrySet()) { ProxyServlet proxyServlet = entry.getKey(); Object value = entry.getValue(); diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java index ca5d433de53..a2d7727dd9f 100644 --- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java +++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java @@ -37,11 +37,9 @@ public class ServletRegistration extends EndpointRegistration { static { ServiceLoader loader = ServiceLoader.load(MultipartSupportFactory.class); - Iterator iterator = loader.iterator(); - - while (iterator.hasNext()) { + for (MultipartSupportFactory element : loader) { try { - factory = iterator.next(); + factory = element; break; } catch (Throwable t) { diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/hook/RegionResolverHook.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/hook/RegionResolverHook.java index 1e724f3e857..13c200808ca 100644 --- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/hook/RegionResolverHook.java +++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/hook/RegionResolverHook.java @@ -137,9 +137,7 @@ public void filterSingletonCollisions(BundleCapability singleton, Collection candidates, boolean singleton) { System.out.println((singleton ? "Singleton" : "Requirer: ") + requirer.getSymbolicName() + "_" + requirer.getVersion() + "[" + getBundleId(requirer) + "]"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ System.out.println(" Candidates: "); //$NON-NLS-1$ - Iterator i = candidates.iterator(); - while (i.hasNext()) { - BundleCapability c = i.next(); + for (BundleCapability c : candidates) { String namespace = c.getNamespace(); if (BundleRevision.PACKAGE_NAMESPACE.equals(namespace)) { BundleRevision providerRevision = c.getRevision(); @@ -157,9 +155,7 @@ private void debugEntry(BundleRevision requirer, Collection ca private void debugExit(BundleRevision requirer, Collection candidates) { System.out.println(" Filtered candidates: "); //$NON-NLS-1$ - Iterator i = candidates.iterator(); - while (i.hasNext()) { - BundleCapability c = i.next(); + for (BundleCapability c : candidates) { String namespace = c.getNamespace(); if (BundleRevision.PACKAGE_NAMESPACE.equals(namespace)) { BundleRevision providerRevision = c.getRevision(); diff --git a/bundles/org.eclipse.equinox.registry/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.registry/META-INF/MANIFEST.MF index 5ada6e86af2..f780efe996a 100644 --- a/bundles/org.eclipse.equinox.registry/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.registry/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.registry;singleton:=true -Bundle-Version: 3.11.100.qualifier +Bundle-Version: 3.11.200.qualifier Bundle-Localization: plugin Export-Package: org.eclipse.core.internal.adapter;x-internal:=true, org.eclipse.core.internal.registry;x-friends:="org.eclipse.core.runtime", diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableReader.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableReader.java index 646e26fd5fe..baf279650b6 100644 --- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableReader.java +++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableReader.java @@ -271,7 +271,7 @@ private ConfigurationElement loadConfigurationElementAndChildren(DataInputStream if (depth + 1 > maxDepth) return ce; - for (int i = 0; i < children.length; i++) { + for (int child : children) { ConfigurationElement tmp = loadConfigurationElementAndChildren(currentStream, extraIs, depth + 1, maxDepth, objectManager, namespaceOwnerId); objectManager.add(tmp, holdObjects); } diff --git a/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/internal/useradmin/UserAdminStore.java b/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/internal/useradmin/UserAdminStore.java index 01a59dc3809..a0cef8ee3ec 100644 --- a/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/internal/useradmin/UserAdminStore.java +++ b/bundles/org.eclipse.equinox.useradmin/src/org/eclipse/equinox/internal/useradmin/UserAdminStore.java @@ -248,10 +248,10 @@ protected void loadRoles() throws BackingStoreException { String[] children = rootNode.node("").childrenNames(); //$NON-NLS-1$ - for (int i = 0; i < children.length; i++) { - if (useradmin.getRole(children[i]) == null) //check to see if it is already loaded + for (String child : children) { + if (useradmin.getRole(child) == null) //check to see if it is already loaded { //(we may have had to load some roles out of - loadRole(rootNode.node(children[i]), null); // order due to dependencies) + loadRole(rootNode.node(child), null); // order due to dependencies) //modified to solve defect 95982 } } @@ -278,12 +278,12 @@ protected void loadRole(Preferences node, Role role) throws BackingStoreExceptio //load properties Preferences propsTypesNode = propsNode.node(typesNode); - for (int i = 0; i < keys.length; i++) { - if (propsTypesNode.getBoolean(keys[i], true)) - value = propsNode.get(keys[i], null); + for (String key : keys) { + if (propsTypesNode.getBoolean(key, true)) + value = propsNode.get(key, null); else - value = propsNode.getByteArray(keys[i], null); - properties.put(keys[i], value, false); + value = propsNode.getByteArray(key, null); + properties.put(key, value, false); } //load credentials @@ -293,12 +293,12 @@ protected void loadRole(Preferences node, Role role) throws BackingStoreExceptio Preferences credTypesNode = credNode.node(UserAdminStore.typesNode); keys = credNode.keys(); UserAdminHashtable credentials = (UserAdminHashtable) ((User) role).getCredentials(); - for (int i = 0; i < keys.length; i++) { - if (credTypesNode.getBoolean(keys[i], true)) - credValue = credNode.get(keys[i], null); + for (String key : keys) { + if (credTypesNode.getBoolean(key, true)) + credValue = credNode.get(key, null); else - credValue = credNode.getByteArray(keys[i], null); - credentials.put(keys[i], credValue, false); + credValue = credNode.getByteArray(key, null); + credentials.put(key, credValue, false); } } @@ -306,13 +306,13 @@ protected void loadRole(Preferences node, Role role) throws BackingStoreExceptio if (type == org.osgi.service.useradmin.Role.GROUP) { Preferences memberNode = node.node(membersNode); keys = memberNode.keys(); - for (int i = 0; i < keys.length; i++) { - value = memberNode.get(keys[i], null); - Role member = (Role) useradmin.getRole(keys[i]); + for (String key : keys) { + value = memberNode.get(key, null); + Role member = (Role) useradmin.getRole(key); if (member == null) //then we have not loaded this one yet, so load it { - loadRole(rootNode.node(keys[i]), null); // modified to solve defect 95982 - member = (Role) useradmin.getRole(keys[i]); + loadRole(rootNode.node(key), null); // modified to solve defect 95982 + member = (Role) useradmin.getRole(key); } if (value.equals(requiredString)) { ((Group) role).addRequiredMember(member, false); diff --git a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/module/MappedList.java b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/module/MappedList.java index 0a9d7ad2846..8f8335fff32 100644 --- a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/module/MappedList.java +++ b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/module/MappedList.java @@ -16,7 +16,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.List; /* @@ -74,9 +73,8 @@ public List getAllValues() { if (getSize() == 0) return empty; ArrayList results = new ArrayList<>(getSize()); - Iterator> iter = internal.values().iterator(); - while (iter.hasNext()) - results.addAll(iter.next()); + for (List element : internal.values()) + results.addAll(element); return results; } diff --git a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/module/ResolverImpl.java b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/module/ResolverImpl.java index 89de26db7c9..e79db308fdc 100644 --- a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/module/ResolverImpl.java +++ b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/module/ResolverImpl.java @@ -1358,19 +1358,18 @@ private void checkCycle(List cycle) { } if (cycle.size() != cycleSize) { //we removed an un-resolvable bundle; must re-resolve remaining cycle - for (int i = 0; i < cycle.size(); i++) { - ResolverBundle cycleBundle = cycle.get(i); + for (ResolverBundle cycleBundle : cycle) { cycleBundle.clearWires(); } List innerCycle = new ArrayList<>(cycle.size()); - for (int i = 0; i < cycle.size(); i++) - resolveBundle(cycle.get(i), innerCycle); + for (ResolverBundle element : cycle) + resolveBundle(element, innerCycle); checkCycle(innerCycle); } else { - for (int i = 0; i < cycle.size(); i++) { + for (ResolverBundle element : cycle) { if (DEBUG || DEBUG_CYCLES) - ResolverImpl.log("Pushing " + cycle.get(i) + " to RESOLVED"); //$NON-NLS-1$ //$NON-NLS-2$ - setBundleResolved(cycle.get(i)); + ResolverImpl.log("Pushing " + element + " to RESOLVED"); //$NON-NLS-1$ //$NON-NLS-2$ + setBundleResolved(element); } } } diff --git a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java index a1f3d16a27e..bdd3a100d44 100644 --- a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java +++ b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java @@ -556,9 +556,8 @@ protected void removeDependencies() { synchronized (this.monitor) { if (dependencies == null) return; - Iterator iter = dependencies.iterator(); - while (iter.hasNext()) { - ((BundleDescriptionImpl) iter.next()).removeDependent(this); + for (BundleDescription element : dependencies) { + ((BundleDescriptionImpl) element).removeDependent(this); } dependencies = null; } @@ -599,8 +598,7 @@ List getBundleDependencies() { if (dependencies == null) return new ArrayList<>(0); ArrayList required = new ArrayList<>(dependencies.size()); - for (Iterator iter = dependencies.iterator(); iter.hasNext();) { - BundleDescription dep = iter.next(); + for (BundleDescription dep : dependencies) { if (dep != this && dep.getHost() == null) required.add(dep); } diff --git a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateDeltaImpl.java b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateDeltaImpl.java index 11b73aaf2fc..58e1c1f7e3e 100644 --- a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateDeltaImpl.java +++ b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateDeltaImpl.java @@ -41,8 +41,7 @@ public BundleDelta[] getChanges() { public BundleDelta[] getChanges(int mask, boolean exact) { synchronized (this.changes) { List result = new ArrayList<>(); - for (Iterator changesIter = changes.values().iterator(); changesIter.hasNext();) { - BundleDelta change = changesIter.next(); + for (BundleDelta change : changes.values()) { if (mask == change.getType() || (!exact && (change.getType() & mask) != 0)) result.add(change); } diff --git a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateHelperImpl.java b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateHelperImpl.java index 8c00533d758..0c0bf2adc3e 100644 --- a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateHelperImpl.java +++ b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateHelperImpl.java @@ -20,7 +20,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -402,8 +401,8 @@ private void buildReferences(BundleDescription description, List refer } private void buildReferences(BundleDescription description, List dependencies, List references) { - for (Iterator iter = dependencies.iterator(); iter.hasNext();) - addReference(description, iter.next(), references); + for (BundleDescription bundleDescription : dependencies) + addReference(description, bundleDescription, references); } private void addReference(BundleDescription description, BundleDescription reference, List references) { diff --git a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateImpl.java b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateImpl.java index cade655f0da..ef6e6cce64c 100644 --- a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateImpl.java +++ b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateImpl.java @@ -26,7 +26,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; @@ -241,8 +240,7 @@ public boolean updateBundle(BundleDescription newDescription) { List infos = disabledBundles.remove(existing); if (infos != null) { List newInfos = new ArrayList<>(infos.size()); - for (Iterator iInfos = infos.iterator(); iInfos.hasNext();) { - DisabledInfo info = iInfos.next(); + for (DisabledInfo info : infos) { newInfos.add(new DisabledInfo(info.getPolicyName(), info.getMessage(), newDescription)); } disabledBundles.put(newDescription, newInfos); @@ -358,8 +356,7 @@ public BundleDescription getBundle(long id) { if (result != null) return result; // need to look in removal pending bundles; - for (Iterator iter = removalPendings.iterator(); iter.hasNext();) { - BundleDescription removedBundle = iter.next(); + for (BundleDescription removedBundle : removalPendings) { if (removedBundle.getBundleId() == id) // just return the first matching id return removedBundle; } @@ -758,15 +755,13 @@ public ExportPackageDescription[] getExportedPackages() { fullyLoad(); synchronized (this.monitor) { List allExportedPackages = new ArrayList<>(); - for (Iterator iter = resolvedBundles.values().iterator(); iter.hasNext();) { - BundleDescription bundle = iter.next(); + for (BundleDescription bundle : resolvedBundles.values()) { ExportPackageDescription[] bundlePackages = bundle.getSelectedExports(); if (bundlePackages == null) continue; Collections.addAll(allExportedPackages, bundlePackages); } - for (Iterator iter = removalPendings.iterator(); iter.hasNext();) { - BundleDescription bundle = iter.next(); + for (BundleDescription bundle : removalPendings) { ExportPackageDescription[] bundlePackages = bundle.getSelectedExports(); if (bundlePackages == null) continue; @@ -825,8 +820,7 @@ void setFactory(StateObjectFactory factory) { public BundleDescription getBundleByLocation(String location) { synchronized (this.monitor) { - for (Iterator i = bundleDescriptions.values().iterator(); i.hasNext();) { - BundleDescription current = i.next(); + for (BundleDescription current : bundleDescriptions.values()) { if (location.equals(current.getLocation())) return current; } @@ -1125,12 +1119,11 @@ private static void addDependents(BundleDescription bundle, Set removed = removalPendings.iterator(); BundleDescription[] result = new BundleDescription[removalPendings.size()]; int i = 0; - while (removed.hasNext()) + for (BundleDescription removalPending : removalPendings) // we return the latest version of the description if it is still contained in the state (bug 287636) - result[i++] = getBundle(removed.next().getBundleId()); + result[i++] = getBundle(removalPending.getBundleId()); return result; } } @@ -1337,9 +1330,7 @@ public void addDisabledInfo(DisabledInfo disabledInfo) { currentInfos.add(disabledInfo); disabledBundles.put(disabledInfo.getBundle(), currentInfos); } else { - Iterator it = currentInfos.iterator(); - while (it.hasNext()) { - DisabledInfo currentInfo = it.next(); + for (DisabledInfo currentInfo : currentInfos) { if (disabledInfo.getPolicyName().equals(currentInfo.getPolicyName())) { currentInfos.remove(currentInfo); break; @@ -1369,9 +1360,7 @@ public DisabledInfo getDisabledInfo(BundleDescription bundle, String policyName) List currentInfos = disabledBundles.get(bundle); if (currentInfos == null) return null; - Iterator it = currentInfos.iterator(); - while (it.hasNext()) { - DisabledInfo currentInfo = it.next(); + for (DisabledInfo currentInfo : currentInfos) { if (currentInfo.getPolicyName().equals(policyName)) { return currentInfo; } @@ -1393,8 +1382,8 @@ public DisabledInfo[] getDisabledInfos(BundleDescription bundle) { DisabledInfo[] getDisabledInfos() { List results = new ArrayList<>(); synchronized (this.monitor) { - for (Iterator> allDisabledInfos = disabledBundles.values().iterator(); allDisabledInfos.hasNext();) - results.addAll(allDisabledInfos.next()); + for (List list : disabledBundles.values()) + results.addAll(list); } return results.toArray(new DisabledInfo[results.size()]); } diff --git a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateReader.java b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateReader.java index ee725f71eb8..36984ea7de4 100644 --- a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateReader.java +++ b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateReader.java @@ -843,19 +843,16 @@ void fullyLoad(BundleDescriptionImpl target) throws IOException { addDependencies(target, toLoad); int skipBytes[] = getSkipBytes(toLoad); // look for the lazy data of the toLoad list - for (int i = 0; i < skipBytes.length; i++) - readBundleDescriptionLazyData(in, skipBytes[i]); + for (int skipByte : skipBytes) + readBundleDescriptionLazyData(in, skipByte); } } private void addDependencies(BundleDescriptionImpl target, List toLoad) { if (toLoad.contains(target) || target.isFullyLoaded()) return; - Iterator load = toLoad.iterator(); int i = 0; - while (load.hasNext()) { - // insert the target into the list sorted by lazy data offsets - BundleDescriptionImpl bundle = load.next(); + for (BundleDescriptionImpl bundle : toLoad) { if (target.getLazyDataOffset() < bundle.getLazyDataOffset()) break; i++; @@ -865,8 +862,8 @@ private void addDependencies(BundleDescriptionImpl target, List deps = target.getBundleDependencies(); - for (Iterator iter = deps.iterator(); iter.hasNext();) - addDependencies((BundleDescriptionImpl) iter.next(), toLoad); + for (BundleDescription dep : deps) + addDependencies((BundleDescriptionImpl) dep, toLoad); } private int[] getSkipBytes(List toLoad) { diff --git a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateWriter.java b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateWriter.java index af183df4908..9f8988b80dd 100644 --- a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateWriter.java +++ b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/StateWriter.java @@ -24,7 +24,6 @@ import java.util.Dictionary; import java.util.Enumeration; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import org.eclipse.osgi.service.resolver.BaseDescription; @@ -257,8 +256,8 @@ private void writeBundleDescription(BundleDescription bundle, DataOutputStream o List dependencies = ((BundleDescriptionImpl) bundle).getBundleDependencies(); out.writeInt(dependencies.size()); - for (Iterator iter = dependencies.iterator(); iter.hasNext();) - writeBundleDescription(iter.next(), out, force); + for (BundleDescription bundleDescription : dependencies) + writeBundleDescription(bundleDescription, out, force); // the rest is lazy loaded data } @@ -511,9 +510,7 @@ private void writeMap(DataOutputStream out, Map source) throws IOExce out.writeInt(0); } else { out.writeInt(source.size()); - Iterator iter = source.keySet().iterator(); - while (iter.hasNext()) { - String key = iter.next(); + for (String key : source.keySet()) { Object value = source.get(key); writeStringOrNull(key, out); if (value instanceof String) { diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationAdminTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationAdminTest.java index 6dbf75c1800..20255da3411 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationAdminTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationAdminTest.java @@ -16,7 +16,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import junit.framework.Test; import junit.framework.TestSuite; @@ -683,8 +682,8 @@ private void doTestCardinality01(String appID, int cardinality, boolean hasMax) fail("Unexpected ApplicationException", e); //$NON-NLS-1$ assertEquals("check error code", ApplicationException.APPLICATION_NOT_LAUNCHABLE, e.getErrorCode()); //$NON-NLS-1$ } finally { - for (Iterator handles = instances.iterator(); handles.hasNext();) { - ((ApplicationHandle) handles.next()).destroy(); + for (Object element : instances) { + ((ApplicationHandle) element).destroy(); } } assertEquals("Did not launch the correct # of concurrent instances", instances.size(), cardinality + (hasMax ? 0 : 1)); //$NON-NLS-1$ @@ -709,8 +708,8 @@ private void doTestMainThreaded(String appID) { fail("Unable to launch a main threaded application", e); //$NON-NLS-1$ assertEquals("check error code", ApplicationException.APPLICATION_NOT_LAUNCHABLE, e.getErrorCode()); //$NON-NLS-1$ } finally { - for (Iterator handles = instances.iterator(); handles.hasNext();) { - ((ApplicationHandle) handles.next()).destroy(); + for (Object element : instances) { + ((ApplicationHandle) element).destroy(); } } assertEquals("Did not launch the correct # of main app instances", instances.size(), 1); //$NON-NLS-1$ @@ -855,8 +854,8 @@ public void testPersistentSchedule02() throws InvalidSyntaxException { args.put("test.arg1", Boolean.TRUE); //$NON-NLS-1$ args.put("test.arg2", Integer.valueOf(34)); //$NON-NLS-1$ args.put("test.arg3", Long.valueOf(34)); //$NON-NLS-1$ - for (Iterator iEntries = args.entrySet().iterator(); iEntries.hasNext();) { - Map.Entry entry = (Map.Entry) iEntries.next(); + for (Object element : args.entrySet()) { + Map.Entry entry = (Map.Entry) element; assertEquals("key: " + entry.getKey(), entry.getValue(), results.get(entry.getKey())); //$NON-NLS-1$ } } catch (InterruptedException e) { @@ -918,8 +917,8 @@ public void testPersistentSchedule05() throws InvalidSyntaxException { args.put("test.arg1", Boolean.TRUE); //$NON-NLS-1$ args.put("test.arg2", Integer.valueOf(34)); //$NON-NLS-1$ args.put("test.arg3", Long.valueOf(34)); //$NON-NLS-1$ - for (Iterator iEntries = args.entrySet().iterator(); iEntries.hasNext();) { - Map.Entry entry = (Map.Entry) iEntries.next(); + for (Object element : args.entrySet()) { + Map.Entry entry = (Map.Entry) element; assertEquals("key: " + entry.getKey(), entry.getValue(), results.get(entry.getKey())); //$NON-NLS-1$ } // should not find the scheduled app anymore diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/debugoptions/DebugOptionsTestCase.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/debugoptions/DebugOptionsTestCase.java index 933fb39c4bf..287eb74ed26 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/debugoptions/DebugOptionsTestCase.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/debugoptions/DebugOptionsTestCase.java @@ -31,7 +31,6 @@ import java.util.Dictionary; import java.util.HashMap; import java.util.Hashtable; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -1391,8 +1390,8 @@ public void optionsChanged(DebugOptions options) { called = true; if (checkValues == null) return; - for (Iterator entries = checkValues.entrySet().iterator(); entries.hasNext();) { - Map.Entry entry = (Entry) entries.next(); + for (Object element : checkValues.entrySet()) { + Map.Entry entry = (Entry) element; String debugValue = options.getOption((String) entry.getKey()); String error = "Value is incorrect for key: " + entry.getKey() + " " + debugValue; //$NON-NLS-1$//$NON-NLS-2$ if (debugValue == null) { diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/BasicTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/BasicTest.java index d6fe813fb82..0a652472a0a 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/BasicTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/BasicTest.java @@ -15,7 +15,6 @@ import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -427,13 +426,13 @@ private void assertIdentityCapability(Capability capability, String symbolicName // The type attribute contains the resource type. assertType(type, (String) capability.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE)); Map attributes = capability.getAttributes(); - for (Iterator iEntries = arbitraryAttrs.entrySet().iterator(); iEntries.hasNext();) { - Map.Entry entry = (Entry) iEntries.next(); + for (Object element : arbitraryAttrs.entrySet()) { + Map.Entry entry = (Entry) element; assertEquals("Wrong attribute: " + entry.getKey(), entry.getValue(), attributes.get(entry.getKey())); } Map directives = capability.getDirectives(); - for (Iterator iEntries = arbitraryDirs.entrySet().iterator(); iEntries.hasNext();) { - Map.Entry entry = (Entry) iEntries.next(); + for (Object element : arbitraryDirs.entrySet()) { + Map.Entry entry = (Entry) element; assertEquals("Wrong directive: " + entry.getKey(), entry.getValue(), directives.get(entry.getKey())); } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/ResolverHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/ResolverHookTests.java index 0366d72efe9..2b64f2de4e4 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/ResolverHookTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/ResolverHookTests.java @@ -15,7 +15,6 @@ import java.util.Arrays; import java.util.Collection; -import java.util.Iterator; import org.osgi.framework.Bundle; import org.osgi.framework.ServiceRegistration; import org.osgi.framework.hooks.resolver.ResolverHook; @@ -44,8 +43,8 @@ public void filterSingletonCollisions(BundleCapability singleton, Collection col assertEquals("Wrong namespace", IdentityNamespace.IDENTITY_NAMESPACE, singleton.getNamespace()); assertEquals("Wrong singleton directive", "true", singleton.getDirectives().get(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE)); String symbolicName = (String) singleton.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE); - for (Iterator iCandidates = collisionCandidates.iterator(); iCandidates.hasNext();) { - BundleCapability candidate = (BundleCapability) iCandidates.next(); + for (Object collisionCandidate : collisionCandidates) { + BundleCapability candidate = (BundleCapability) collisionCandidate; assertEquals("Wrong namespace", IdentityNamespace.IDENTITY_NAMESPACE, candidate.getNamespace()); assertEquals("Wrong singleton directive", "true", candidate.getDirectives().get(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE)); assertEquals("Wrong symbolic name", symbolicName, (String) candidate.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE)); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/OSGiCapabilityTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/OSGiCapabilityTest.java index 73505e1cfc8..112900c3508 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/OSGiCapabilityTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/OSGiCapabilityTest.java @@ -588,8 +588,8 @@ public void testOSGiCardinality() throws BundleException { expectedCapabilities.addAll(p1.getCapabilities("namespace.1")); expectedCapabilities.addAll(p2.getCapabilities("namespace.1")); expectedCapabilities.addAll(p3.getCapabilities("namespace.1")); - for (Iterator iWires = requiredWires.iterator(); iWires.hasNext();) { - BundleWire wire = (BundleWire) iWires.next(); + for (Object requiredWire : requiredWires) { + BundleWire wire = (BundleWire) requiredWire; expectedCapabilities.remove(wire.getCapability()); } assertTrue("Unexpected capability wire: " + requiredWires, expectedCapabilities.isEmpty()); diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java index e952151c65f..aaeda57d26f 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java @@ -25,7 +25,6 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -1475,9 +1474,7 @@ private static void writeMap(Map source, DataOutputStream out, Map iter = source.keySet().iterator(); - while (iter.hasNext()) { - String key = iter.next(); + for (String key : source.keySet()) { Object value = source.get(key); writeString(key, out, objectTable); if (value instanceof String) { diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/container/ComputeNodeOrder.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/container/ComputeNodeOrder.java index 6c0c8cff7a9..b6ad5b1f4e9 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/container/ComputeNodeOrder.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/container/ComputeNodeOrder.java @@ -489,8 +489,8 @@ public static Object[][] computeNodeOrder(Object[] objects, Object[][] reference final Digraph g2 = new Digraph(); // add vertexes List resortedVertexes = g1.idsByDFSFinishTime(false); - for (Iterator it = resortedVertexes.iterator(); it.hasNext();) - g2.addVertex(it.next()); + for (Object object : resortedVertexes) + g2.addVertex(object); // add edges for (Object[] reference : references) { g2.addEdge(reference[0], reference[1]); diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/FrameworkDebugOptions.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/FrameworkDebugOptions.java index 8451ae28543..ffa400f3dfa 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/FrameworkDebugOptions.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/FrameworkDebugOptions.java @@ -20,8 +20,8 @@ import java.net.URL; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import java.util.Set; import org.eclipse.osgi.internal.framework.EquinoxConfiguration; @@ -192,10 +192,8 @@ String[] getAllOptions() { synchronized (lock) { if (options != null) { optionsArray = new String[options.size()]; - final Iterator> entrySetIterator = options.entrySet().iterator(); int i = 0; - while (entrySetIterator.hasNext()) { - Map.Entry entry = entrySetIterator.next(); + for (Entry entry : options.entrySet()) { optionsArray[i] = ((String) entry.getKey()) + "=" + ((String) entry.getValue()); //$NON-NLS-1$ i++; } @@ -292,8 +290,8 @@ public void setOptions(Map ops) { } fireChangesTo = new HashSet<>(); // first check for removals - for (Iterator keys = options.keySet().iterator(); keys.hasNext();) { - String key = (String) keys.next(); + for (Object object : options.keySet()) { + String key = (String) object; if (!newOptions.containsKey(key)) { String symbolicName = getSymbolicName(key); if (symbolicName != null) @@ -313,8 +311,8 @@ public void setOptions(Map ops) { options = newOptions; } if (fireChangesTo != null) - for (Iterator iChanges = fireChangesTo.iterator(); iChanges.hasNext();) - optionsChanged(iChanges.next()); + for (String string : fireChangesTo) + optionsChanged(string); } /* diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/ContextFinder.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/ContextFinder.java index c0f53476452..4fce976028f 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/ContextFinder.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/ContextFinder.java @@ -21,7 +21,6 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; import org.eclipse.osgi.internal.loader.BundleLoader; @@ -137,9 +136,9 @@ protected Class loadClass(String arg0, boolean arg1) throws ClassNotFoundExce try { List toConsult = findClassLoaders(); - for (Iterator loaders = toConsult.iterator(); loaders.hasNext();) + for (ClassLoader classLoader : toConsult) try { - return loaders.next().loadClass(arg0); + return classLoader.loadClass(arg0); } catch (ClassNotFoundException e) { // go to the next class loader } @@ -157,8 +156,8 @@ public URL getResource(String arg0) { return null; try { List toConsult = findClassLoaders(); - for (Iterator loaders = toConsult.iterator(); loaders.hasNext();) { - URL result = loaders.next().getResource(arg0); + for (ClassLoader classLoader : toConsult) { + URL result = classLoader.getResource(arg0); if (result != null) return result; // go to the next class loader @@ -178,8 +177,8 @@ public Enumeration getResources(String arg0) throws IOException { try { List toConsult = findClassLoaders(); Enumeration result = null; - for (Iterator loaders = toConsult.iterator(); loaders.hasNext();) { - result = loaders.next().getResources(arg0); + for (ClassLoader classLoader : toConsult) { + result = classLoader.getResources(arg0); if (result != null && result.hasMoreElements()) { // For context finder we do not compound results after this first loader that has resources break; diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java index 00a8670d7b2..9a852810b80 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java @@ -1134,10 +1134,10 @@ private static int parseVersionInt(String value) { // try up to the first non-number char StringBuilder sb = new StringBuilder(value.length()); char[] chars = value.toCharArray(); - for (int i = 0; i < chars.length; i++) { - if (!Character.isDigit(chars[i])) + for (char element : chars) { + if (!Character.isDigit(element)) break; - sb.append(chars[i]); + sb.append(element); } if (sb.length() > 0) return Integer.parseInt(sb.toString()); diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java index bec29997842..66e9254bb25 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java @@ -1158,8 +1158,8 @@ private static void checkRegisterServicePermission(String[] names) { if (sm == null) { return; } - for (int i = 0, len = names.length; i < len; i++) { - sm.checkPermission(new ServicePermission(names[i], ServicePermission.REGISTER)); + for (String name : names) { + sm.checkPermission(new ServicePermission(name, ServicePermission.REGISTER)); } } @@ -1203,15 +1203,15 @@ public ClassLoader run() { return serviceObject.getClass().getClassLoader(); } }); - for (int i = 0, len = clazzes.length; i < len; i++) { + for (String element : clazzes) { try { - Class serviceClazz = cl == null ? Class.forName(clazzes[i]) : cl.loadClass(clazzes[i]); + Class serviceClazz = cl == null ? Class.forName(element) : cl.loadClass(element); if (!serviceClazz.isInstance(serviceObject)) - return clazzes[i]; + return element; } catch (ClassNotFoundException e) { //This check is rarely done - if (extensiveCheckServiceClass(clazzes[i], serviceObject.getClass())) - return clazzes[i]; + if (extensiveCheckServiceClass(element, serviceObject.getClass())) + return element; } } return null; @@ -1221,8 +1221,8 @@ private static boolean extensiveCheckServiceClass(String clazz, Class service if (clazz.equals(serviceClazz.getName())) return false; Class[] interfaces = serviceClazz.getInterfaces(); - for (int i = 0, len = interfaces.length; i < len; i++) - if (!extensiveCheckServiceClass(clazz, interfaces[i])) + for (Class element : interfaces) + if (!extensiveCheckServiceClass(clazz, element)) return false; Class superClazz = serviceClazz.getSuperclass(); if (superClazz != null) @@ -1234,8 +1234,8 @@ private static boolean extensiveCheckServiceClass(String clazz, Class service static boolean isAssignableTo(BundleContextImpl context, String clazz, ServiceReferenceImpl reference) { Bundle bundle = context.getBundleImpl(); String[] clazzes = reference.getClasses(); - for (int i = 0, len = clazzes.length; i < len; i++) - if (!reference.getRegistration().isAssignableTo(bundle, clazzes[i], clazzes[i] == clazz)) + for (String element : clazzes) + if (!reference.getRegistration().isAssignableTo(bundle, element, element == clazz)) return false; return true; } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/SignedBundleHook.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/SignedBundleHook.java index 4a86f0a7678..684e2a75dc7 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/SignedBundleHook.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/SignedBundleHook.java @@ -28,7 +28,6 @@ import java.util.ArrayList; import java.util.Dictionary; import java.util.Hashtable; -import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; import org.eclipse.osgi.framework.log.FrameworkLogEntry; @@ -147,8 +146,8 @@ void frameworkStop(BundleContext bc) { systemTrustEngineReg = null; } if (osgiTrustEngineReg != null) { - for (Iterator> it = osgiTrustEngineReg.iterator(); it.hasNext();) - it.next().unregister(); + for (ServiceRegistration serviceRegistration : osgiTrustEngineReg) + serviceRegistration.unregister(); osgiTrustEngineReg = null; } if (trustEngineTracker != null) { diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/TrustEngineListener.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/TrustEngineListener.java index 7d58ac37544..a575d15129c 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/TrustEngineListener.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/TrustEngineListener.java @@ -14,7 +14,6 @@ import java.security.cert.Certificate; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import org.eclipse.osgi.internal.framework.EquinoxConfiguration; import org.eclipse.osgi.internal.signedcontent.SignedContentFromBundleFile.BaseSignerInfo; @@ -85,8 +84,8 @@ public void removedTrustAnchor(Certificate anchor) { } } // remove trust anchors from untrusted signers - for (Iterator untrusted = untrustedSigners.iterator(); untrusted.hasNext();) - ((BaseSignerInfo) untrusted.next()).setTrustAnchor(null); + for (SignerInfo untrustedSigner : untrustedSigners) + ((BaseSignerInfo) untrustedSigner).setTrustAnchor(null); // re-establish trust for (Bundle bundle : usingAnchor) { SignedContentFromBundleFile signedContent = getSignedContent(bundle); diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java index 0386c817231..3c0654b2fb3 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java @@ -785,9 +785,9 @@ private void setStorageHooks(Generation generation) throws BundleException { } List> factories = new ArrayList<>(getConfiguration().getHookRegistry().getStorageHookFactories()); List> hooks = new ArrayList<>(factories.size()); - for (Iterator> iFactories = factories.iterator(); iFactories.hasNext();) { + for (StorageHookFactory storageHookFactory : factories) { @SuppressWarnings("unchecked") - StorageHookFactory> next = (StorageHookFactory>) iFactories.next(); + StorageHookFactory> next = (StorageHookFactory>) storageHookFactory; StorageHook hook = next.createStorageHookAndValidateFactoryClass(generation); if (hook != null) { hooks.add(hook); @@ -1615,9 +1615,9 @@ private void loadStorageHookData(List generations, DataInputStream i } } // now we need to recover for any hooks that are left - for (Iterator> iFactories = factories.iterator(); iFactories.hasNext();) { + for (StorageHookFactory storageHookFactory : factories) { @SuppressWarnings("unchecked") - StorageHookFactory> next = (StorageHookFactory>) iFactories.next(); + StorageHookFactory> next = (StorageHookFactory>) storageHookFactory; // recover by reinitializing the hook for (Generation generation : generations) { if (generation.getBundleInfo().getBundleId() == 0) { diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java index 0b552129a61..2bda7c6d22a 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java @@ -27,7 +27,6 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Hashtable; -import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; @@ -269,14 +268,14 @@ InputStream getInputStream(int generation, int openMask) throws IOException { File textFile = null; InputStream textIS = null; - for (int idx = 0; idx < generations.length; idx++) { + for (int generation2 : generations) { if (generation != 0) { - if (generations[idx] > generation || (failOnPrimary && generations[idx] != generation)) + if (generation2 > generation || (failOnPrimary && generation2 != generation)) continue; } File file; - if (generations[idx] != 0) - file = new File(parent, name + '.' + generations[idx]); + if (generation2 != 0) + file = new File(parent, name + '.' + generation2); else file = referenceFile; InputStream is = null; @@ -632,11 +631,11 @@ public static boolean delete(File deleteFile) { String name = deleteFile.getName(); File parent = new File(deleteFile.getParent()); synchronized (cacheFiles) { - for (int idx = 0; idx < generations.length; idx++) { + for (int generation : generations) { // base files (.0 in generations[]) will never be deleted - if (generations[idx] == 0) + if (generation == 0) continue; - File file = new File(parent, name + '.' + generations[idx]); + File file = new File(parent, name + '.' + generation); if (file.exists()) { file.delete(); } @@ -675,8 +674,8 @@ public static String[] getBaseFiles(File directory) throws IOException { } files = new String[list.size()]; int idx = 0; - for (Iterator iter = list.iterator(); iter.hasNext();) { - files[idx++] = iter.next(); + for (String string : list) { + files[idx++] = string; } return files; }