maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Schulte (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (MNG-6105) properties.internal.SystemProperties.addSystemProperties() is not really thread-safe
Date Fri, 14 Oct 2016 22:51:20 GMT

    [ https://issues.apache.org/jira/browse/MNG-6105?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15576795#comment-15576795
] 

Christian Schulte commented on MNG-6105:
----------------------------------------

I'd do it that way:

{code}
package org.apache.maven.properties.internal;

/*
 * 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.
 */

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @since 3.2.3
 */
public class SystemProperties
{

    /**
     * Thread-safe System.properties copy implementation.
     *
     * @see "https://issues.apache.org/jira/browse/MNG-5670"
     */
    public static void addSystemProperties( Properties props )
    {
        props.putAll( getSystemProperties() );
    }

    /**
     * Returns System.properties copy.
     */
    public static Properties getSystemProperties()
    {
        final Properties systemProperties = new Properties();

        try ( final ByteArrayOutputStream out = new ByteArrayOutputStream() )
        {
            System.getProperties().store( out, null );

            try ( final ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray()
) )
            {
                systemProperties.load( in );
            }
        }
        catch ( final IOException e )
        {
            throw new AssertionError( "Unexpected IO error copying system properties.", e
);
        }

        return systemProperties;
    }

}
{code}


> properties.internal.SystemProperties.addSystemProperties() is not really thread-safe
> ------------------------------------------------------------------------------------
>
>                 Key: MNG-6105
>                 URL: https://issues.apache.org/jira/browse/MNG-6105
>             Project: Maven
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.3.9
>         Environment: Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00)
> Maven home: /usr/maven/default
> Java version: 1.8.0_102, vendor: Oracle Corporation
> Java home: /usr/java/jdk1.8.0_102/jre
> Default locale: en_US, platform encoding: UTF-8
> OS name: "linux", version: "2.6.32-431.29.2.el6.x86_64", arch: "amd64", family: "unix"
>            Reporter: Falko Modler
>            Assignee: Guillaume Boué
>
> We got a rather large Maven project with a couble of modules that execute {{maven-assembly-plugin}}.
Our build runs in parallel mode via {{-Tx}}.
> From time to time we are seeing following exception causing the respective build to fail:
> {noformat}
> [ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single
(assembly-zip) on project some-module: Execution assembly-zip of goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single
failed. NullPointerException -> [Help 1]
> org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single
(assembly-zip) on project some-module: Execution assembly-zip of goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single
failed.
> 	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
> 	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
> 	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
> 	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
> 	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:185)
> 	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:181)
> 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
> 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> 	at java.lang.Thread.run(Thread.java:745)
> Caused by: org.apache.maven.plugin.PluginExecutionException: Execution assembly-zip of
goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single failed.
> 	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
> 	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
> 	... 11 more
> Caused by: java.lang.NullPointerException
> 	at java.util.Hashtable.put(Hashtable.java:459)
> 	at org.apache.maven.properties.internal.SystemProperties.addSystemProperties(SystemProperties.java:38)
> 	at org.apache.maven.project.artifact.MavenMetadataSource.getSystemProperties(MavenMetadataSource.java:756)
> 	at org.apache.maven.project.artifact.MavenMetadataSource.retrieveRelocatedProject(MavenMetadataSource.java:574)
> 	at org.apache.maven.project.artifact.MavenMetadataSource.retrieve(MavenMetadataSource.java:190)
> 	at org.apache.maven.repository.legacy.resolver.DefaultLegacyArtifactCollector.recurse(DefaultLegacyArtifactCollector.java:532)
> 	at org.apache.maven.repository.legacy.resolver.DefaultLegacyArtifactCollector.recurse(DefaultLegacyArtifactCollector.java:584)
> 	at org.apache.maven.repository.legacy.resolver.DefaultLegacyArtifactCollector.collect(DefaultLegacyArtifactCollector.java:144)
> 	at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:493)
> 	at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveWithExceptions(DefaultArtifactResolver.java:348)
> 	at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:342)
> 	at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:321)
> 	at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:286)
> 	at org.apache.maven.plugin.assembly.artifact.DefaultDependencyResolver.resolveTransitively(DefaultDependencyResolver.java:253)
> 	at org.apache.maven.plugin.assembly.artifact.DefaultDependencyResolver.resolveDependencySets(DefaultDependencyResolver.java:169)
> 	at org.apache.maven.plugin.assembly.archive.phase.DependencySetAssemblyPhase.execute(DependencySetAssemblyPhase.java:94)
> 	at org.apache.maven.plugin.assembly.archive.DefaultAssemblyArchiver.createArchive(DefaultAssemblyArchiver.java:178)
> 	at org.apache.maven.plugin.assembly.mojos.AbstractAssemblyMojo.execute(AbstractAssemblyMojo.java:484)
> 	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
> 	... 12 more
> [ERROR] 
> [ERROR] Re-run Maven using the -X switch to enable full debug logging.
> [ERROR] 
> [ERROR] For more information about the errors and possible solutions, please read the
following articles:
> [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
> {noformat}
> There seems to be concurrent system property removal while {{properties.internal.SystemProperties}}
is iterating over the previously calculated property keys:
> {code:java|title=https://github.com/apache/maven/blob/maven-3.3.9/maven-core/src/main/java/org/apache/maven/properties/internal/SystemProperties.java}
>     /**
>      * Thread-safe System.properties copy implementation.
>      *
>      * @see "https://issues.apache.org/jira/browse/MNG-5670"
>      */
>     public static void addSystemProperties( Properties props )
>     {
>         for ( String key : System.getProperties().stringPropertyNames() )
>         {
>             props.put( key, System.getProperty( key ) );
>         }
> }
> {code}
> {{System.getProperty( key )}} possibly yields a {{null}} value which {{Hashtable/Properties}}
does not accept.
> *Possible solutions*:
> - refrain from adding {{null}} by explicitly checking for it
> - replace {{for}}-loop with {{props.addAll(System.getProperties().clone())}}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message