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.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.properties.internal.EnvironmentUtils; 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.DefaultMetadataResolutionRequest;
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
@ -752,7 +753,7 @@ public class MavenMetadataSource
EnvironmentUtils.addEnvVars( props ); EnvironmentUtils.addEnvVars( props );
props.putAll( System.getProperties() ); SystemProperties.addSystemProperties( props );
return 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.File;
import java.io.IOException; import java.io.IOException;
import org.apache.maven.execution.MavenExecutionRequest; 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.DefaultSettingsBuildingRequest;
import org.apache.maven.settings.building.SettingsBuilder; import org.apache.maven.settings.building.SettingsBuilder;
import org.apache.maven.settings.building.SettingsBuildingException; import org.apache.maven.settings.building.SettingsBuildingException;
@ -71,7 +72,7 @@ public class DefaultMavenSettingsBuilder
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
request.setUserSettingsFile( userSettingsFile ); request.setUserSettingsFile( userSettingsFile );
request.setGlobalSettingsFile( globalSettingsFile ); request.setGlobalSettingsFile( globalSettingsFile );
request.setSystemProperties( System.getProperties() ); request.setSystemProperties( SystemProperties.getSystemProperties() );
return build( request ); return build( request );
} }

View File

@ -59,6 +59,7 @@ import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.model.building.ModelProcessor; import org.apache.maven.model.building.ModelProcessor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.properties.internal.EnvironmentUtils; 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.DefaultSettingsBuildingRequest;
import org.apache.maven.settings.building.SettingsBuilder; import org.apache.maven.settings.building.SettingsBuilder;
import org.apache.maven.settings.building.SettingsBuildingRequest; import org.apache.maven.settings.building.SettingsBuildingRequest;
@ -1163,8 +1164,8 @@ public class MavenCli
} }
} }
systemProperties.putAll( System.getProperties() ); SystemProperties.addSystemProperties( systemProperties );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Properties containing info about the currently running version of Maven // Properties containing info about the currently running version of Maven
// These override any corresponding properties set on the command line // These override any corresponding properties set on the command line

View File

@ -106,7 +106,11 @@ public class DefaultSettingsBuildingRequest
if ( systemProperties != null ) if ( systemProperties != null )
{ {
this.systemProperties = new Properties(); 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 else
{ {