Skip to content

Commit

Permalink
HeaderMap: replace with a concurrent #329
Browse files Browse the repository at this point in the history
to avoid ConcurrentModificationException
#329
  • Loading branch information
EcljpseB0T authored and jukzi committed Feb 15, 2024
1 parent f13bc87 commit 1b16948
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;

import org.eclipse.pde.internal.core.ibundle.IBundle;
import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
import org.eclipse.pde.internal.core.text.bundle.ManifestHeader;
import org.eclipse.pde.internal.core.util.HeaderMap;
import org.osgi.framework.Constants;

public class Bundle extends BundleObject implements IBundle {
private static final long serialVersionUID = 1L;
private final Map<String, IManifestHeader> fDocumentHeaders = new HeaderMap<>();
private final Map<String, IManifestHeader> fDocumentHeaders = new ConcurrentSkipListMap<>(
String::compareToIgnoreCase);

@Override
public void setHeader(String key, String value) {
Expand Down Expand Up @@ -100,7 +101,7 @@ public IManifestHeader getManifestHeader(String key) {

@Override
public Map<String, IManifestHeader> getManifestHeaders() {
HeaderMap<String, IManifestHeader> copy = new HeaderMap<>();
Map<String, IManifestHeader> copy = new ConcurrentSkipListMap<>(String::compareToIgnoreCase);
copy.putAll(fDocumentHeaders);
return copy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.function.Consumer;

import javax.xml.parsers.ParserConfigurationException;
Expand All @@ -45,7 +46,6 @@
import org.eclipse.pde.internal.core.plugin.ExternalFragmentModel;
import org.eclipse.pde.internal.core.plugin.ExternalPluginModel;
import org.eclipse.pde.internal.core.plugin.ExternalPluginModelBase;
import org.eclipse.pde.internal.core.util.HeaderMap;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -143,7 +143,8 @@ protected String getPluginID(String manifest) throws IOException {

if (OSGiFile.exists()) {
try (FileInputStream manifestStream = new FileInputStream(OSGiFile)) {
Map<String, String> headers = ManifestElement.parseBundleManifest(manifestStream, new HeaderMap<>());
Map<String, String> headers = ManifestElement.parseBundleManifest(manifestStream,
new ConcurrentSkipListMap<>(String::compareToIgnoreCase));
String value = headers.get(Constants.BUNDLE_SYMBOLICNAME);
if (value == null) {
return null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
Expand All @@ -23,13 +24,13 @@
import org.eclipse.pde.internal.core.ibundle.IBundleModel;
import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
import org.eclipse.pde.internal.core.text.IDocumentKey;
import org.eclipse.pde.internal.core.util.HeaderMap;
import org.osgi.framework.Constants;

public class Bundle implements IBundle {

private final BundleModel fModel;
private final Map<String, IManifestHeader> fDocumentHeaders = new HeaderMap<>();
private final Map<String, IManifestHeader> fDocumentHeaders = new ConcurrentSkipListMap<>(
String::compareToIgnoreCase);

public Bundle(BundleModel model) {
fModel = model;
Expand Down Expand Up @@ -149,7 +150,7 @@ public IManifestHeader getManifestHeader(String key) {

@Override
public Map<String, IManifestHeader> getManifestHeaders() {
HeaderMap<String, IManifestHeader> copy = new HeaderMap<>();
Map<String, IManifestHeader> copy = new ConcurrentSkipListMap<>(String::compareToIgnoreCase);
copy.putAll(fDocumentHeaders);
return copy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentSkipListMap;

import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IJavaProject;
Expand All @@ -48,7 +49,6 @@
import org.eclipse.pde.core.plugin.ModelEntry;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.internal.core.ICoreConstants;
import org.eclipse.pde.internal.core.util.HeaderMap;
import org.eclipse.pde.internal.core.util.PDEJavaHelper;
import org.eclipse.pde.internal.ui.PDEPluginImages;
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
Expand Down Expand Up @@ -125,7 +125,7 @@ public char[] getCompletionProposalAutoActivationCharacters() {
}

protected final void parseDocument(IDocument doc) {
fHeaders = new HeaderMap<>();
fHeaders = new ConcurrentSkipListMap<>(String::compareToIgnoreCase);
int numLines = doc.getNumberOfLines();
int offset = 0;
// since we are searching the line after the current line to peak ahead to see if it is a new header, start with the index of 1
Expand Down

0 comments on commit 1b16948

Please sign in to comment.