Maven 2 & 3

mvn -Da=" " throws an excepltion

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Trivial Trivial
  • Resolution: Fixed
  • Affects Version/s: 2.0.8
  • Fix Version/s: 3.0-beta-1
  • Component/s: Command Line
  • Labels:
    None
  • Complexity:
    Intermediate
  • Number of attachments :
    0

Description

Doing,

mvn -Da=" "

throws,

---------------------------------------------------
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.AbstractStringBuilder.setLength(AbstractStringBuilder.java:146)
at java.lang.StringBuffer.setLength(StringBuffer.java:154)
at org.apache.maven.cli.MavenCli$CLIManager.cleanArgs(MavenCli.java:793)
at org.apache.maven.cli.MavenCli$CLIManager.parse(MavenCli.java:746)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

Issue Links

Activity

Hide
Dominic Mitchell added a comment -

I've just seen this as well:

% mvn release:prepare -DscmCommentPrefix='FOO-139 '
---------------------------------------------------
constituent[0]: file:/usr/local/apache-maven-2.0.9/lib/maven-2.0.9-uber.jar
---------------------------------------------------
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.AbstractStringBuilder.setLength(AbstractStringBuilder.java:143)
        at java.lang.StringBuffer.setLength(StringBuffer.java:153)
        at org.apache.maven.cli.MavenCli$CLIManager.cleanArgs(MavenCli.java:824)
        at org.apache.maven.cli.MavenCli$CLIManager.parse(MavenCli.java:777)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:103)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

It's quite useful to have a trailing space in the scmCommentPrefix, as otherwise it gets joined up with the automatically generated commit message and looks rather ugly.

Show
Dominic Mitchell added a comment - I've just seen this as well:
% mvn release:prepare -DscmCommentPrefix='FOO-139 '
---------------------------------------------------
constituent[0]: file:/usr/local/apache-maven-2.0.9/lib/maven-2.0.9-uber.jar
---------------------------------------------------
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.AbstractStringBuilder.setLength(AbstractStringBuilder.java:143)
        at java.lang.StringBuffer.setLength(StringBuffer.java:153)
        at org.apache.maven.cli.MavenCli$CLIManager.cleanArgs(MavenCli.java:824)
        at org.apache.maven.cli.MavenCli$CLIManager.parse(MavenCli.java:777)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:103)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
It's quite useful to have a trailing space in the scmCommentPrefix, as otherwise it gets joined up with the automatically generated commit message and looks rather ugly.
Hide
Paul Benedict added a comment -

The duplicated issue (MNG-3994) has 2.0.10 has an affected version, but I can't reproduce it using 2.0.10. I tried these commands:

mvn -Da=" "
mvn -Da=""
mvn validate -Da=" "
Show
Paul Benedict added a comment - The duplicated issue (MNG-3994) has 2.0.10 has an affected version, but I can't reproduce it using 2.0.10. I tried these commands:
mvn -Da=" "
mvn -Da=""
mvn validate -Da=" "
Hide
Brett Porter added a comment -

I can definitely reproduce it here (Mac OS X)

Show
Brett Porter added a comment - I can definitely reproduce it here (Mac OS X)
Hide
Paul Benedict added a comment -

I wonder if it is an OS-specific issue? I am on Windows. The report indicates a unix problem and OS X is, unless I am mistaken, a port of unix.

Show
Paul Benedict added a comment - I wonder if it is an OS-specific issue? I am on Windows. The report indicates a unix problem and OS X is, unless I am mistaken, a port of unix.
Hide
Benjamin Bentmann added a comment - - edited

The problem originates from the Unix shell script we use to launch Maven, the relevant part:

QUOTED_ARGS=""
while [ "$1" != "" ] ; do
  QUOTED_ARGS="$QUOTED_ARGS \"$1\""
  shift
done

[...]

exec [...] $QUOTED_ARGS

While I can't explain it, this screws up the parameter passing and makes -D=" " parse as the two parameters "-D= and "

There seem to be two possible solutions to this:
a) Nuke the QUOTED_ARGS variable and use the special variable $@ instead, i.e.

exec [...] "$@"

b) Mimic Ant's launch script and do

exec_cmd="exec [...] $QUOTED_ARGS"
eval $exec_cmd

Personally, I don't know enough about Unix shell scripting to judge which of these is preferrable or might have unwanted side effects so Unix gurus please speak up.

Show
Benjamin Bentmann added a comment - - edited The problem originates from the Unix shell script we use to launch Maven, the relevant part:
QUOTED_ARGS=""
while [ "$1" != "" ] ; do
  QUOTED_ARGS="$QUOTED_ARGS \"$1\""
  shift
done

[...]

exec [...] $QUOTED_ARGS
While I can't explain it, this screws up the parameter passing and makes -D=" " parse as the two parameters "-D= and " There seem to be two possible solutions to this: a) Nuke the QUOTED_ARGS variable and use the special variable $@ instead, i.e.
exec [...] "$@"
b) Mimic Ant's launch script and do
exec_cmd="exec [...] $QUOTED_ARGS"
eval $exec_cmd
Personally, I don't know enough about Unix shell scripting to judge which of these is preferrable or might have unwanted side effects so Unix gurus please speak up.
Hide
Benjamin Bentmann added a comment -

It appears approach b) is more helpful as it also fixes a related issue with the MAVEN_OPTS variable. Right now

export "MAVEN_OPTS=-Dthe.prop=\"x y\""

makes mvn also fail (Exception in thread "main" java.lang.NoClassDefFoundError: y").

Show
Benjamin Bentmann added a comment - It appears approach b) is more helpful as it also fixes a related issue with the MAVEN_OPTS variable. Right now
export "MAVEN_OPTS=-Dthe.prop=\"x y\""
makes mvn also fail (Exception in thread "main" java.lang.NoClassDefFoundError: y").
Hide
Benjamin Bentmann added a comment -

Fixed in r928714.

Show
Benjamin Bentmann added a comment - Fixed in r928714.
Hide
Jesse Glick added a comment -

Caused a regression; see: MNG-4767

Show
Jesse Glick added a comment - Caused a regression; see: MNG-4767

People

Vote (2)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: