Skip to content

Commit 9f5a4d9

Browse files
committed
Make XHTML example more null-safe
1 parent b6c2c59 commit 9f5a4d9

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/test/java/org/apache/commons/cli/example/XhtmlHelpAppendable.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1919
import java.io.IOException;
2020
import java.util.Collection;
2121
import java.util.List;
22+
import java.util.Objects;
2223

2324
import org.apache.commons.cli.help.FilterHelpAppendable;
2425
import org.apache.commons.cli.help.TableDefinition;
@@ -46,7 +47,7 @@ public void appendHeader(final int level, final CharSequence text) throws IOExce
4647
if (level < 1) {
4748
throw new IllegalArgumentException("level must be at least 1");
4849
}
49-
appendFormat("<h%s>%s</h%1$s>%n", level, StringEscapeUtils.escapeHtml4(text.toString()));
50+
appendFormat("<h%s>%s</h%1$s>%n", level, StringEscapeUtils.escapeHtml4(Objects.toString(text)));
5051
}
5152
}
5253

@@ -62,7 +63,7 @@ public void appendList(final boolean ordered, final Collection<CharSequence> lis
6263
@Override
6364
public void appendParagraph(final CharSequence paragraph) throws IOException {
6465
if (StringUtils.isNotEmpty(paragraph)) {
65-
appendFormat("<p>%s</p>%n", StringEscapeUtils.escapeHtml4(paragraph.toString()));
66+
appendFormat("<p>%s</p>%n", StringEscapeUtils.escapeHtml4(Objects.toString(paragraph)));
6667
}
6768
}
6869

@@ -93,6 +94,6 @@ public void appendTable(final TableDefinition table) throws IOException {
9394

9495
@Override
9596
public void appendTitle(final CharSequence title) throws IOException {
96-
appendFormat("<span class='commons_cli_title'>%s</span>%n", StringEscapeUtils.escapeHtml4(title.toString()));
97+
appendFormat("<span class='commons_cli_title'>%s</span>%n", StringEscapeUtils.escapeHtml4(Objects.toString(title)));
9798
}
9899
}

0 commit comments

Comments
 (0)