On Sat, 29 Jun 2024 19:10:51 GMT, Shaojin Wen <[email protected]> wrote:
>> src/java.base/share/classes/java/lang/StringFormat.java line 48:
>>
>>> 46: static String format(String format, Object... args) {
>>> 47: if (args != null) {
>>> 48: int off = format.indexOf('%');
>>
>> nit: instead of not null check, should this short circuit for null/empty
>> args?
>>
>> Suggestion:
>>
>> if (args == null || args.length == 0) {
>> // no formatting to be done
>> return format;
>> }
>>
>> int off = format.indexOf('%');
>
> j.u.Formatter supports args == null
When `args == null` or `args.length == 0`, then the format string can still
contain `%%` or `%n`, and those will be formatted to `"%"` and
[`System.lineSeparator()`] respectively.
[`System.lineSeparator()`]:
https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/System.html#lineSeparator()
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/19956#discussion_r1661292677