MNG-5670 guard against ConcurrentModificationException iterating over System properties

Signed-off-by: Igor Fedorenko <ifedorenko@apache.org>
This commit is contained in:
Igor Fedorenko 2014-07-30 07:57:53 +04:00
parent e3000a09c9
commit 8980f67b9b
5 changed files with 63 additions and 5 deletions

View File

@ -68,6 +68,7 @@
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.properties.internal.EnvironmentUtils;
import org.apache.maven.properties.internal.SystemProperties;
import org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest;
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
import org.codehaus.plexus.PlexusContainer;
@ -752,7 +753,7 @@ private Properties getSystemProperties()
EnvironmentUtils.addEnvVars( props );
props.putAll( System.getProperties() );
SystemProperties.addSystemProperties( props );
return props;
}

View File

@ -0,0 +1,51 @@
package org.apache.maven.properties.internal;
import java.util.Properties;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @since 3.2.3
*/
public class SystemProperties
{
/**
* Thread-safe System.properties copy implementation.
*
* @see http://jira.codehaus.org/browse/MNG-5670
*/
public static void addSystemProperties( Properties props )
{
for ( String key : System.getProperties().stringPropertyNames() )
{
props.put( key, System.getProperty( key ) );
}
}
/**
* Returns System.properties copy.
*/
public static Properties getSystemProperties()
{
Properties systemProperties = new Properties();
addSystemProperties( systemProperties );
return systemProperties;
}
}

View File

@ -23,6 +23,7 @@
import java.io.IOException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.properties.internal.SystemProperties;
import org.apache.maven.settings.building.DefaultSettingsBuildingRequest;
import org.apache.maven.settings.building.SettingsBuilder;
import org.apache.maven.settings.building.SettingsBuildingException;
@ -71,7 +72,7 @@ public Settings buildSettings( File userSettingsFile )
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
request.setUserSettingsFile( userSettingsFile );
request.setGlobalSettingsFile( globalSettingsFile );
request.setSystemProperties( System.getProperties() );
request.setSystemProperties( SystemProperties.getSystemProperties() );
return build( request );
}

View File

@ -59,6 +59,7 @@
import org.apache.maven.model.building.ModelProcessor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.properties.internal.EnvironmentUtils;
import org.apache.maven.properties.internal.SystemProperties;
import org.apache.maven.settings.building.DefaultSettingsBuildingRequest;
import org.apache.maven.settings.building.SettingsBuilder;
import org.apache.maven.settings.building.SettingsBuildingRequest;
@ -1163,7 +1164,7 @@ static void populateProperties( CommandLine commandLine, Properties systemProper
}
}
systemProperties.putAll( System.getProperties() );
SystemProperties.addSystemProperties( systemProperties );
// ----------------------------------------------------------------------
// Properties containing info about the currently running version of Maven

View File

@ -106,7 +106,11 @@ public DefaultSettingsBuildingRequest setSystemProperties( Properties systemProp
if ( systemProperties != null )
{
this.systemProperties = new Properties();
this.systemProperties.putAll( systemProperties );
// MNG-5670 guard against ConcurrentModificationException
for ( String key : System.getProperties().stringPropertyNames() )
{
this.systemProperties.put( key, System.getProperty( key ) );
}
}
else
{