Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSHARED-1050] Fix ConcurrentModificationException for maven-filtering #98

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/main/java/org/apache/maven/shared/filtering/BaseFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public List<FilterWrapper> getDefaultFilterWrappers(final AbstractMavenFiltering
//
if (request.getMavenSession() != null) {
// User properties have precedence over system properties
baseProps.putAll(request.getMavenSession().getSystemProperties());
baseProps.putAll(request.getMavenSession().getUserProperties());
putAll(baseProps, request.getMavenSession().getSystemProperties());
putAll(baseProps, request.getMavenSession().getUserProperties());
}

// now we build properties to use for resources interpolation
Expand All @@ -119,8 +119,8 @@ public List<FilterWrapper> getDefaultFilterWrappers(final AbstractMavenFiltering
request.getMavenProject() != null ? request.getMavenProject().getBasedir() : new File(".");

loadProperties(filterProperties, basedir, request.getFileFilters(), baseProps);
if (filterProperties.size() < 1) {
filterProperties.putAll(baseProps);
if (filterProperties.isEmpty()) {
putAll(filterProperties, baseProps);
}

if (request.getMavenProject() != null) {
Expand All @@ -144,13 +144,13 @@ public List<FilterWrapper> getDefaultFilterWrappers(final AbstractMavenFiltering
}
if (request.getMavenSession() != null) {
// User properties have precedence over system properties
filterProperties.putAll(request.getMavenSession().getSystemProperties());
filterProperties.putAll(request.getMavenSession().getUserProperties());
putAll(filterProperties, request.getMavenSession().getSystemProperties());
putAll(filterProperties, request.getMavenSession().getUserProperties());
}

if (request.getAdditionalProperties() != null) {
// additional properties wins
filterProperties.putAll(request.getAdditionalProperties());
putAll(filterProperties, request.getAdditionalProperties());
}

List<FilterWrapper> defaultFilterWrappers =
Expand Down Expand Up @@ -180,6 +180,13 @@ public List<FilterWrapper> getDefaultFilterWrappers(final AbstractMavenFiltering
return defaultFilterWrappers;
}

@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
private static void putAll(Properties filterProperties, Properties request) {
synchronized (request) {
filterProperties.putAll(request);
}
}

/**
* default visibility only for testing reason !
*/
Expand All @@ -188,7 +195,7 @@ void loadProperties(
throws MavenFilteringException {
if (propertiesFilePaths != null) {
Properties workProperties = new Properties();
workProperties.putAll(baseProps);
putAll(workProperties, baseProps);

for (String filterFile : propertiesFilePaths) {
if (filterFile == null || filterFile.trim().isEmpty()) {
Expand All @@ -198,8 +205,8 @@ void loadProperties(
try {
File propFile = FilteringUtils.resolveFile(basedir, filterFile);
Properties properties = PropertyUtils.loadPropertyFile(propFile, workProperties, getLogger());
filterProperties.putAll(properties);
workProperties.putAll(properties);
putAll(filterProperties, properties);
putAll(workProperties, properties);
} catch (IOException e) {
throw new MavenFilteringException("Error loading property file '" + filterFile + "'", e);
}
Expand Down