Skip to content

Commit b2a7a9c

Browse files
committed
Fix potential concurrency issue with project properties
1 parent 3aef4e9 commit b2a7a9c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/properties/impl/ProjectPropertiesManagerImpl.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
import java.io.StringWriter;
1212
import java.nio.charset.StandardCharsets;
1313
import java.util.ArrayList;
14-
import java.util.HashMap;
1514
import java.util.HashSet;
1615
import java.util.List;
17-
import java.util.Map;
1816
import java.util.Set;
17+
import java.util.concurrent.ConcurrentHashMap;
18+
import java.util.concurrent.ConcurrentMap;
1919
import javax.xml.bind.DataBindingException;
2020
import javax.xml.bind.JAXBContext;
2121
import javax.xml.bind.JAXBElement;
@@ -56,7 +56,7 @@ public class ProjectPropertiesManagerImpl implements IProjectPropertiesManager {
5656

5757
private static final String PROPERTIES_FILE = ".pmd";
5858

59-
private final Map<IProject, IProjectProperties> projectsProperties = new HashMap<IProject, IProjectProperties>();
59+
private final ConcurrentMap<IProject, IProjectProperties> projectsProperties = new ConcurrentHashMap<IProject, IProjectProperties>();
6060

6161
private static final JAXBContext JAXB_CONTEXT = initJaxbContext();
6262

@@ -80,11 +80,16 @@ public IProjectProperties loadProjectProperties(final IProject project) throws P
8080
try {
8181
IProjectProperties projectProperties = this.projectsProperties.get(project);
8282
if (projectProperties == null) {
83-
LOG.debug("Creating new poject properties for " + project.getName());
84-
projectProperties = new PropertiesFactoryImpl().newProjectProperties(project, this);
83+
LOG.debug("Creating new poject properties for {}", project.getName());
84+
IProjectProperties projectPropertiesNew = new PropertiesFactoryImpl().newProjectProperties(project, this);
8585
final ProjectPropertiesTO to = readProjectProperties(project);
86-
fillProjectProperties(projectProperties, to);
87-
this.projectsProperties.put(project, projectProperties);
86+
fillProjectProperties(projectPropertiesNew, to);
87+
projectProperties = this.projectsProperties.putIfAbsent(project, projectPropertiesNew);
88+
if (projectProperties == null) {
89+
projectProperties = projectPropertiesNew;
90+
} else {
91+
LOG.debug("project properties already existed for {}", project.getName());
92+
}
8893
}
8994

9095
// if the ruleset is stored in the project always reload it

0 commit comments

Comments
 (0)