8204229: Formatter and String.format ignore the width with the percent modifier (%5%)
authorsherman
Fri, 08 Jun 2018 10:09:40 -0700
changeset 50475 0e25d6367884
parent 50474 5d905cc4c358
child 50476 30d5bca69eae
8204229: Formatter and String.format ignore the width with the percent modifier (%5%) Reviewed-by: jlaskey
src/java.base/share/classes/java/util/Formatter.java
test/jdk/java/util/Formatter/Basic-X.java.template
test/jdk/java/util/Formatter/Basic.java
test/jdk/java/util/Formatter/BasicBigDecimal.java
test/jdk/java/util/Formatter/BasicBigInteger.java
test/jdk/java/util/Formatter/BasicBoolean.java
test/jdk/java/util/Formatter/BasicBooleanObject.java
test/jdk/java/util/Formatter/BasicByte.java
test/jdk/java/util/Formatter/BasicByteObject.java
test/jdk/java/util/Formatter/BasicChar.java
test/jdk/java/util/Formatter/BasicCharObject.java
test/jdk/java/util/Formatter/BasicDateTime.java
test/jdk/java/util/Formatter/BasicDouble.java
test/jdk/java/util/Formatter/BasicDoubleObject.java
test/jdk/java/util/Formatter/BasicFloat.java
test/jdk/java/util/Formatter/BasicFloatObject.java
test/jdk/java/util/Formatter/BasicInt.java
test/jdk/java/util/Formatter/BasicIntObject.java
test/jdk/java/util/Formatter/BasicLong.java
test/jdk/java/util/Formatter/BasicLongObject.java
test/jdk/java/util/Formatter/BasicShort.java
test/jdk/java/util/Formatter/BasicShortObject.java
test/jdk/java/util/Formatter/genBasic.sh
--- a/src/java.base/share/classes/java/util/Formatter.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/src/java.base/share/classes/java/util/Formatter.java	Fri Jun 08 10:09:40 2018 -0700
@@ -2914,7 +2914,7 @@
                 a.append(System.lineSeparator());
                 break;
             case Conversion.PERCENT_SIGN:
-                a.append('%');
+                print("%", l);
                 break;
             default:
                 assert false;
--- a/test/jdk/java/util/Formatter/Basic-X.java.template	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/Basic-X.java.template	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/Basic.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/Basic.java	Fri Jun 08 10:09:40 2018 -0700
@@ -26,7 +26,7 @@
  * @bug 4906370 4962433 4973103 4989961 5005818 5031150 4970931 4989491 5002937
  *      5005104 5007745 5061412 5055180 5066788 5088703 6317248 6318369 6320122
  *      6344623 6369500 6534606 6282094 6286592 6476425 5063507 6469160 6476168
- *      8059175
+ *      8059175 8204229
  *
  * @modules java.base
  * @run shell/timeout=240 Basic.sh
--- a/test/jdk/java/util/Formatter/BasicBigDecimal.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicBigDecimal.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicBigInteger.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicBigInteger.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicBoolean.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicBoolean.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicBooleanObject.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicBooleanObject.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicByte.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicByte.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicByteObject.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicByteObject.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicChar.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicChar.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicCharObject.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicCharObject.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicDateTime.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicDateTime.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicDouble.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicDouble.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicDoubleObject.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicDoubleObject.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicFloat.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicFloat.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicFloatObject.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicFloatObject.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicInt.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicInt.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicIntObject.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicIntObject.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicLong.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicLong.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicLongObject.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicLongObject.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicShort.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicShort.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/BasicShortObject.java	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/BasicShortObject.java	Fri Jun 08 10:09:40 2018 -0700
@@ -1792,6 +1792,15 @@
         //---------------------------------------------------------------------
         test("%%", "%", (Object)null);
         test("%%", "%", "");
+
+        test("%5%", "    %", (Object)null);
+        test("%5%", "    %", "");
+        test("%-5%", "%    ", (Object)null);
+        test("%-5%", "%    ", "");
+
+        tryCatch("%.5%", IllegalFormatPrecisionException.class);
+        tryCatch("%5.5%", IllegalFormatPrecisionException.class);
+
         tryCatch("%%%", UnknownFormatConversionException.class);
         // perhaps an IllegalFormatArgumentIndexException should be defined?
         tryCatch("%<%", IllegalFormatFlagsException.class);
--- a/test/jdk/java/util/Formatter/genBasic.sh	Fri Jun 08 09:37:52 2018 -0700
+++ b/test/jdk/java/util/Formatter/genBasic.sh	Fri Jun 08 10:09:40 2018 -0700
@@ -23,7 +23,7 @@
 # questions.
 #
 
-javac -d . ../../../../make/src/classes/build/tools/spp/Spp.java
+javac -d . ../../../../../make/jdk/src/classes/build/tools/spp/Spp.java
 
 gen() {
 #  if [ $3 = "true" ]