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

Empty <argument> tag adds null to args #132

Closed
Anders-E opened this issue May 16, 2019 · 1 comment
Closed

Empty <argument> tag adds null to args #132

Anders-E opened this issue May 16, 2019 · 1 comment

Comments

@Anders-E
Copy link
Contributor

Anders-E commented May 16, 2019

I'm not sure if this is intended but any empty <argument> tag adds null to String[] args.

I noticed this since it caused a NullPointerException when trying to parse arguments with Apache CLI. Stacktrace:

java.lang.NullPointerException
    at org.apache.commons.cli.DefaultParser.handleToken (DefaultParser.java:237)
    at org.apache.commons.cli.DefaultParser.parse (DefaultParser.java:120)
    at org.apache.commons.cli.DefaultParser.parse (DefaultParser.java:76)
    at org.apache.commons.cli.DefaultParser.parse (DefaultParser.java:60)
    [...]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:282)
    at java.lang.Thread.run (Thread.java:834)

The reason for me occasionally using an empty <argument> tag is that I'm using a little workaround for combining CLI-arguments with arguments specified within pom.xml as such:

<properties>
    <!-- My additional args from CLI -->
    <doc.args/>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>com.my.main.Class</mainClass>
                <arguments>
                    <!-- My default args -->
                    <argument>-a</argument>
                    <argument>myDefaultArgA</argument>
                    <argument>-b</argument>
                    <argument>myDefaultArgB</argument>

                    <!-- Append my CLI args -->
                    <argument>${doc.args}</argument>
                </arguments>
            </configuration>
        </plugin>
    </plugins>
</build>

As of now, I have to keep a placeholder to avoid the crash:

<properties>
    <doc.args>placeholder</doc.args>
</properties>

Which I don't like since the placeholder still gets passed on to the program. Shouldn't an empty <argument> tag not add anything to String[] args at all?

@Anders-E Anders-E changed the title Empty <argument> tag throws NullPointerException Empty <argument> tag not really empty? May 16, 2019
@Anders-E Anders-E changed the title Empty <argument> tag not really empty? Empty <argument> tag adds null to args May 17, 2019
@ctubbsii
Copy link

An empty argument tag should add an empty string. See my comment on #133 (comment)

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