Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not unset or set empty environment variables. #11

Closed
parched opened this issue Aug 25, 2016 · 17 comments
Closed

Can not unset or set empty environment variables. #11

parched opened this issue Aug 25, 2016 · 17 comments
Assignees
Milestone

Comments

@parched
Copy link

parched commented Aug 25, 2016

If you try to set an environment variable to empty it throws a null pointer exception.

I think this is because maven treats empty as null and ProcessBuilder.environment() doesn't handle null values.

A solution would be to check for any keys with null values in environmentVariables and then remove them from ProcessBuilder.environment()

@ksclarke ksclarke self-assigned this Aug 25, 2016
@cowwoc
Copy link
Collaborator

cowwoc commented Dec 2, 2016

@parched I should be able to fix this quickly if you provide a stack-trace.

@parched
Copy link
Author

parched commented Dec 2, 2016

@cowwoc Like this?

$ mvn -e package
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building XXXX 0.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- cmake-maven-plugin:2.8.11-b4:generate (generate) @ XXX ---
[INFO] Configured Artifact: com.googlecode.cmake-maven-project:cmake-binaries:linux:2.8.11-b4:jar
[INFO] cmake-binaries-2.8.11-b4-linux.jar already unpacked.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.702s
[INFO] Finished at: Fri Dec 02 16:56:16 GMT 2016
[INFO] Final Memory: 12M/303M
[INFO] ------------------------------------------------------------------------
 [ERROR] Failed to execute goal com.googlecode.cmake-maven-project:cmake-maven-plugin:2.8.11-b4:generate (generate) on project XXXX: Execution generate of goal com.googlecode.cmake-maven-project:cmake-maven-plugin:2.8.11-b4:generate failed. NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.googlecode.cmake-maven-project:cmake-maven-plugin:2.8.11-b4:generate (generate) on project XXXX: Execution generate of goal com.googlecode.cmake-maven-project:cmake-maven-plugin:2.8.11-b4:generate failed.
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
	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:84)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution generate of goal com.googlecode.cmake-maven-project:cmake-maven-plugin:2.8.11-b4:generate failed.
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:115)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
	... 19 more
Caused by: java.lang.NullPointerException
	at java.lang.ProcessEnvironment.validateValue(ProcessEnvironment.java:120)
	at java.lang.ProcessEnvironment.access$400(ProcessEnvironment.java:61)
	at java.lang.ProcessEnvironment$Value.valueOf(ProcessEnvironment.java:203)
	at java.lang.ProcessEnvironment$StringEnvironment.put(ProcessEnvironment.java:243)
	at java.lang.ProcessEnvironment$StringEnvironment.put(ProcessEnvironment.java:221)
	at java.util.AbstractMap.putAll(AbstractMap.java:281)
	at com.googlecode.cmakemavenproject.GenerateMojo.execute(GenerateMojo.java:156)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
	... 20 more
[ERROR] 
[ERROR] 

@ksclarke ksclarke removed their assignment Dec 2, 2016
@cowwoc cowwoc self-assigned this Dec 2, 2016
@cowwoc
Copy link
Collaborator

cowwoc commented Dec 2, 2016

I am having a hard time reproducing this problem. I tried this configuration:

<environmentVariables>
	<key></key>
	<key2>null</key2>
</environmentVariables>

and it worked fine. I suspect this was fixed in a newer dependency than you are running.

What configuration, platform, JDK, and version of CMake plugin are you using? Can you try reproducing the problem with the 3.7.0-b1-SNAPSHOT version of the plugin?

@parched
Copy link
Author

parched commented Dec 2, 2016

Ok yes, your <key></key> should have reproduced it if it was still broken.

I will check everything on Monday, but from memory and looking at that error message, Linux with JDK 8, 2.8.11-b4.

@cowwoc
Copy link
Collaborator

cowwoc commented Dec 2, 2016

Okay, so I think this is fixed. For reference, I am using JDK8 update 112 under Windows. If you still see the problem, try upgrading to update 112.

We'll wait for your report on Monday :)

@cowwoc
Copy link
Collaborator

cowwoc commented Dec 3, 2016

I've released 3.7.0-b1 (non-SNAPSHOT) so you can test against that instead.

@parched
Copy link
Author

parched commented Dec 5, 2016

Hi @cowwoc, I have tried 3.7.0-b1 with java 1.8.0_112 and I still get the exception. Maybe the difference is that I'm using Linux.

@cowwoc
Copy link
Collaborator

cowwoc commented Dec 5, 2016

@parched Thanks for the report. I'll take a look (on Linux) later on this week.

Please send me a pom.xml that triggers the exception if you have one; otherwise, I'll work without it.

@parched
Copy link
Author

parched commented Dec 5, 2016

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>XXXX</artifactId>
    <groupId>com.test</groupId>
    <version>0.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>com.googlecode.cmake-maven-project</groupId>
                <artifactId>cmake-maven-plugin</artifactId>
                <version>3.7.0-b1</version>
                <executions>
                    <execution>
                        <id>generate</id>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                        <configuration>
                            <sourcePath>.</sourcePath>
                            <targetPath>build</targetPath>
                            <generator>Ninja</generator>
                            <classifier>linux-amd64</classifier>
                            <environmentVariables>
                                <SOME_ENV_VAR/>
                            </environmentVariables>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

cowwoc pushed a commit that referenced this issue Dec 11, 2016
…se its behavior is OS-specific.

Attempting to fix NullPointerException on Linux when passing null values: #11
@cowwoc
Copy link
Collaborator

cowwoc commented Dec 11, 2016

Thanks for the testcase. I reproduced the problem and I believe it is fixed in 3.7.0-b2-SNAPSHOT. If you confirm I will make an official release.

@parched
Copy link
Author

parched commented Dec 11, 2016

Hi @cowwoc, I will try and test if I get a chance. Looking at the code changes though, it looks like the nullptr exception will be stopped by just ignoring the variable it rather than setting it to empty which is the goal.

@cowwoc
Copy link
Collaborator

cowwoc commented Dec 11, 2016

@parched My mistake. I misunderstood the goal. Please try the updated SNAPSHOT which sets an empty value instead.

@parched
Copy link
Author

parched commented Dec 11, 2016

@cowwoc that looks better. Unfortunately I'm on holiday for a month so won't be able to test it soon. If that example I posted works for you though I'm happy to close this.

@cowwoc
Copy link
Collaborator

cowwoc commented Dec 11, 2016

Sounds good. I'll make a release and you can confirm that this is closed when you get back. (Have a great time!)

@cowwoc
Copy link
Collaborator

cowwoc commented Apr 5, 2017

Hey @parched,

Can you please try version 3.7.2-b1? I fixed this issue a while back but forgot to have you verify the fix.

@parched
Copy link
Author

parched commented Oct 16, 2018

Sorry for the long delay, we finally got around to upgrading to 3.7.2-b1 and the issue is indeed fixed. Thank you!

@parched parched closed this as completed Oct 16, 2018
@cowwoc
Copy link
Collaborator

cowwoc commented Oct 16, 2018

Excellent, thanks for letting us know.

@cowwoc cowwoc modified the milestones: 3.14.5-b1, 3.7.2-b1 Jun 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants