Skip to content

[MSHARED-969] Environment variable with null value #282

Closed

Description

@jira-importer

Slawomir Jaranowski opened MSHARED-969 and commented

When we add environment variable with null value then to executed process is pass variable with "null" as string.

Variable with null value should not be set, when executed process will try to get this variable will receive null as we expect.


Affects: maven-shared-utils-3.3.3

Issue Links:

  • MINVOKER-273 Environment variable with empty value
    ("causes")
  • MSHARED-971 System environment variable are always added to maven-invoker

Remote Links:

Activity

  1. jira-importer commented on Dec 29, 2020

    @jira-importer
    Author

    Markus Karg commented

    At least on Windows it is impossible to store null in env vars. According to Windows API description doing so will remove the variable from the environment. Can other OS experts confirm that this is the same on Linux, MacOS, etc? If so, I would be +1 for fixing this issue.

  2. jira-importer commented on Dec 29, 2020

    @jira-importer
    Author

    Slawomir Jaranowski commented

    In fixed code system environment is not set yet - it happens later.

    if ( workingDir == null )
    {
    process = Runtime.getRuntime().exec( getShellCommandline(), environment );
    }
    else
    {
    if ( !workingDir.exists() )
    {
    throw new CommandLineException(
    "Working directory \"" + workingDir.getPath() + "\" does not exist!" );
    }
    else if ( !workingDir.isDirectory() )
    {
    throw new CommandLineException(
    "Path \"" + workingDir.getPath() + "\" does not specify a directory." );
    }
    process = Runtime.getRuntime().exec( getShellCommandline(), environment, workingDir );

    by call:
    {{}}

    String[] environment = getEnvironmentVariables();
    ...
    process = Runtime.getRuntime().exec( getShellCommandline(), environment ); 

    }}I fixed method {{getEnvironmentVariables()

    In original code we never have null as environment value

    environmentVars[i] = name + "=" + value;

    if value was null - it was replaced by "null" string.

  3. jira-importer commented on Dec 29, 2020

    @jira-importer
    Author

    Slawomir Jaranowski commented

    After my fix we have another feature, we can remove some variable from system environment.

    In method getEnvironmentVariables first is called addSystemEnvironment which copied current system variable to local list, and when variable with the same name exist it is not copied from system.

    Next in getEnvironmentVariables we filter variables wich have null value and in consequence we can filter system variables.

    I added unit test to confirm this behavior.

     

  4. jira-importer commented on Dec 29, 2020

    @jira-importer
    Author

    Slawomir Jaranowski commented

    and some other discovery MSHARED-971

  5. added
    bug
    priority:major
    on Jul 3, 2025
  6. removed
    priority:major
    on Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions