slawekjaranowski commented on a change in pull request #68:
URL: https://github.com/apache/maven-shared-utils/pull/68#discussion_r549725461
##########
File path: src/main/java/org/apache/maven/shared/utils/cli/Commandline.java
##########
@@ -241,15 +241,16 @@ public void addSystemEnvironment()
public String[] getEnvironmentVariables()
{
addSystemEnvironment();
- String[] environmentVars = new String[envVars.size()];
- int i = 0;
+ List<String> environmentVars = new ArrayList<>();
for ( String name : envVars.keySet() )
{
String value = envVars.get( name );
- environmentVars[i] = name + "=" + value;
- i++;
+ if ( value != null )
+ {
+ environmentVars.add( name + "=" + value );
+ }
}
- return environmentVars;
+ return environmentVars.toArray( new String[0] );
Review comment:
From InteliJ inspection:
> In older Java versions using pre-sized array was recommended, as the
reflection call which is necessary to create an array of proper size was quite
slow. However since late updates of OpenJDK 6 this call was intrinsified,
making the performance of the empty array version the same and sometimes even
better, compared to the pre-sized version. Also passing pre-sized array is
dangerous for a concurrent or synchronized collection as a data race is
possible between the size and toArray call which may result in extra nulls at
the end of the array, if the collection was concurrently shrunk during the
operation.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]