Hari Nair created CLI-353:
-----------------------------
Summary: HelpFormatter.printHelp() hangs with multiline strings
Key: CLI-353
URL: https://issues.apache.org/jira/browse/CLI-353
Project: Commons CLI
Issue Type: Bug
Components: CLI-1.x
Affects Versions: 1.10.0
Reporter: Hari Nair
If the header or footer is a multi-line String that ends with a blank line,
printHelp() will hang.
{code:java}
StringBuilder help = new StringBuilder();
TextHelpAppendable tha = new TextHelpAppendable(help);
org.apache.commons.cli.help.HelpFormatter formatter =
org.apache.commons.cli.help.HelpFormatter.builder()
.setHelpAppendable(tha)
.get();
try {
formatter.printHelp(
String.format("%s [options]",
this.getClass().getSimpleName()),
"""
header""",
formatter.sort(options),
"""
footer""",
false);
return help.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
{code}
This will work; adding a blank line to the end of header or footer will cause
printHelp() to hang:
{code:java}
formatter.printHelp(
String.format("%s [options]",
this.getClass().getSimpleName()),
"""
header
""",
formatter.sort(options),
"""
footer""",
false);
{code}
This did not happen with 1.9.0.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)