Skip to content

Commit e0d9319

Browse files
committed
Remove usages of HashMap functions that are not thread-safe.
- Removes the usages of the underlying HashMap functions on Properties objects that lack synchronization and are not thread safe.
1 parent a3efadb commit e0d9319

File tree

6 files changed

+17
-19
lines changed

6 files changed

+17
-19
lines changed

core/src/main/java/pl/project13/core/GitDataProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ protected SimpleDateFormat getSimpleDateFormatWithTimeZone() {
245245
protected void maybePut(@Nonnull Properties properties, String key, SupplierEx<String> value)
246246
throws GitCommitIdExecutionException {
247247
String keyWithPrefix = prefixDot + key;
248-
if (properties.containsKey(keyWithPrefix)) {
248+
if (properties.stringPropertyNames().contains(keyWithPrefix)) {
249249
String propertyValue = properties.getProperty(keyWithPrefix);
250250
log.info("Using cached {} with value {}", keyWithPrefix, propertyValue);
251251
} else if (PropertiesFilterer.isIncluded(keyWithPrefix, includeOnlyProperties, excludeProperties)) {

core/src/main/java/pl/project13/core/PropertiesFileGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public void maybeGeneratePropertiesFile(@Nonnull Properties localProperties, Fil
7575

7676
final String buildTimeProperty = prefixDot + GitCommitPropertyConstant.BUILD_TIME;
7777

78-
propertiesCopy.remove(buildTimeProperty);
79-
persistedProperties.remove(buildTimeProperty);
78+
propertiesCopy.setProperty(buildTimeProperty, null);
79+
persistedProperties.setProperty(buildTimeProperty, null);
8080

8181
shouldGenerate = !propertiesCopy.equals(persistedProperties);
8282
} catch (CannotReadFileException ex) {

core/src/main/java/pl/project13/core/cibuild/BuildServerDataProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private void loadBuildHostData(@Nonnull Properties properties) {
168168

169169
protected void maybePut(@Nonnull Properties properties, @Nonnull String key, Supplier<String> supplier) {
170170
String keyWithPrefix = prefixDot + key;
171-
if (properties.containsKey(keyWithPrefix)) {
171+
if (properties.stringPropertyNames().contains(keyWithPrefix)) {
172172
String propertyValue = properties.getProperty(keyWithPrefix);
173173
log.info("Using cached {} with value {}", keyWithPrefix, propertyValue);
174174
} else if (PropertiesFilterer.isIncluded(keyWithPrefix, includeOnlyProperties, excludeProperties)) {

core/src/main/java/pl/project13/core/util/PropertyManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void putWithoutPrefix(@Nonnull Properties properties, String key,
3030
if (!isNotEmpty(value)) {
3131
value = "Unknown";
3232
}
33-
properties.put(key, value);
33+
properties.setProperty(key, value);
3434
}
3535

3636
private static boolean isNotEmpty(@Nullable String value) {

maven/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,9 @@ private void loadBuildData(Properties properties) {
564564
}
565565

566566
private void publishPropertiesInto(Properties p) {
567-
p.putAll(properties);
567+
for (String propertyName : properties.stringPropertyNames()) {
568+
p.setProperty(propertyName, properties.getProperty(propertyName));
569+
}
568570
}
569571

570572
/**
@@ -603,9 +605,8 @@ private File lookupGitDirectory() throws GitCommitIdExecutionException {
603605
}
604606

605607
private void logProperties() {
606-
for (Object key : properties.keySet()) {
607-
String keyString = key.toString();
608-
log.info("including property {} in results", keyString);
608+
for (String propertyName : properties.stringPropertyNames()) {
609+
log.info("including property {} in results", propertyName);
609610
}
610611
}
611612

maven/src/main/java/pl/project13/maven/git/PropertiesReplacer.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,18 @@ public void performReplacement(Properties properties, List<ReplacementProperty>
5050
}
5151

5252
private void performReplacementOnAllGeneratedProperties(Properties properties, ReplacementProperty replacementProperty) {
53-
Map<Object, Object> propertiesToBeAdded = new HashMap<>();
54-
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
55-
String key = (String)entry.getKey();
56-
String content = (String)entry.getValue();
53+
for (String propertyName : properties.stringPropertyNames()) {
54+
String content = properties.getProperty(propertyName);
5755
String result = performReplacement(replacementProperty, content);
5856
if ((replacementProperty.getPropertyOutputSuffix() != null) && (!replacementProperty.getPropertyOutputSuffix().isEmpty())) {
59-
String newPropertyKey = key + "." + replacementProperty.getPropertyOutputSuffix();
60-
propertiesToBeAdded.put(newPropertyKey, result);
61-
log.info("apply replace on property " + key + " and save to " + newPropertyKey + ": original value '" + content + "' with '" + result + "'");
57+
String newPropertyKey = propertyName + "." + replacementProperty.getPropertyOutputSuffix();
58+
properties.setProperty(newPropertyKey, result);
59+
log.info("apply replace on property " + propertyName + " and save to " + newPropertyKey + ": original value '" + content + "' with '" + result + "'");
6260
} else {
63-
entry.setValue(result);
64-
log.info("apply replace on property " + key + ": original value '" + content + "' with '" + result + "'");
61+
properties.setProperty(propertyName, result);
62+
log.info("apply replace on property " + propertyName + ": original value '" + content + "' with '" + result + "'");
6563
}
6664
}
67-
properties.putAll(propertiesToBeAdded);
6865
}
6966

7067
private void performReplacementOnSingleProperty(Properties properties, ReplacementProperty replacementProperty, String propertyKey) {

0 commit comments

Comments
 (0)