Java 8 RFR: 6178739 - Formatter - Zero padding flag with zero width

Brian Burkhalter brian.burkhalter at oracle.com
Fri Jun 28 19:10:59 UTC 2013


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


More information about the core-libs-dev mailing list