Java 8 RFR: 6178739 - Formatter - Zero padding flag with zero width
Joe Darcy
joe.darcy at oracle.com
Tue Jul 2 00:37:45 UTC 2013
On 06/28/2013 12:10 PM, Brian Burkhalter wrote:
> Continuing this thread
>
> http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-June/018326.html
>
> with respect to this issue
>
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6178739
>
> this Request for Review proposes the following change to the Formatter javadoc specification:
>
> diff -r 8d577b3a6ca4 src/share/classes/java/util/Formatter.java
> --- a/src/share/classes/java/util/Formatter.java Fri Jun 28 11:09:10 2013 -0700
> +++ b/src/share/classes/java/util/Formatter.java Fri Jun 28 11:58:45 2013 -0700
> @@ -190,7 +190,7 @@
> * <p> The optional <i>flags</i> is a set of characters that modify the output
> * format. The set of valid flags depends on the conversion.
> *
> - * <p> The optional <i>width</i> is a non-negative decimal integer indicating
> + * <p> The optional <i>width</i> is a positive decimal integer indicating
> * the minimum number of characters to be written to the output.
> *
> * <p> The optional <i>precision</i> is a non-negative decimal integer usually
>
> The change is to require the field width to be positive rather than non-negative. Allowing a zero minimum field width seems meaningless. This matches the current behavior as defined by the format specifier regular expression:
>
> private static final String formatSpecifier
> = "%(\\d+\\$)?([-#+ 0,(\\<]*)?(\\d+)?(\\.\\d+)?([tT])?([a-zA-Z%])";
>
> A CCC request for the above would naturally need to be approved if this is change were deemed acceptable.
>
> An alternative, as previously stated, would be to handle cases like %0.4f specially but this seems to violate the letter of the specification as currently written. It would however match the behavior of C and not require a CCC request, FWIW.
>
> Thanks,
>
> Brian
Hello,
Our default policy when a case like this is found is to change the
specification to match the implementation.
While matching the C behavior is generally desirable, if no one has
requested that in the many years Formatter has been in the platform, I
think it is reasonable to change the specification to require a positive
argument in this case.
Cheers,
-Joe
More information about the core-libs-dev
mailing list