Thursday 13 December 2012

JDK7 surprise

Noticed quite an un-documented change in JDK7 windows command-line argument parsing reging quotes escaping and spaces:


Now execute java -cp . ArgTest "-Dfoo=""foo"" <bar>"

With Sun Oracle JDK 1.3.1_18 / 1.4.2_12 / 1.5.0_07 / 6u21 / 6u33 / 6u38:

arg0:-Dfoo="foo
arg1:<bar>

(yes I keep old JDKs around for fun)


With Oracle JDK 7u00 / 7u03 / 7u07:

arg0:-Dfoo="foo" <bar>

One can argue that it's better (and closer to unix java parsing behavior, although not yet identical), another one can argue that compatibility time is over, I'm not picking sides on this one.

Now let's watch all tooling break !
(in my case it was gerrit + gradle + jenkins)

Note:
Strangely enough, escaping quotes with '\' works for all versions (and unix as well), but some guys (read Jenkins) seem to prefer quote doubling.

Note2:
Windows argument parsing (e.g. in batch files) has the exact opposite behavior, and will split the args unless the double quoting is used.

No comments: