8204229: Formatter and String.format ignore the width with the percent modifier (%5%)

Reviewed-by: jlaskey
This commit is contained in:
Xueming Shen 2018-06-08 10:09:40 -07:00
parent acdef788f0
commit f56c0b79d8
23 changed files with 183 additions and 3 deletions

View file

@ -2914,7 +2914,7 @@ public final class Formatter implements Closeable, Flushable {
a.append(System.lineSeparator()); a.append(System.lineSeparator());
break; break;
case Conversion.PERCENT_SIGN: case Conversion.PERCENT_SIGN:
a.append('%'); print("%", l);
break; break;
default: default:
assert false; assert false;

View file

@ -1792,6 +1792,15 @@ public class Basic$Type$ extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -26,7 +26,7 @@
* @bug 4906370 4962433 4973103 4989961 5005818 5031150 4970931 4989491 5002937 * @bug 4906370 4962433 4973103 4989961 5005818 5031150 4970931 4989491 5002937
* 5005104 5007745 5061412 5055180 5066788 5088703 6317248 6318369 6320122 * 5005104 5007745 5061412 5055180 5066788 5088703 6317248 6318369 6320122
* 6344623 6369500 6534606 6282094 6286592 6476425 5063507 6469160 6476168 * 6344623 6369500 6534606 6282094 6286592 6476425 5063507 6469160 6476168
* 8059175 * 8059175 8204229
* *
* @modules java.base * @modules java.base
* @run shell/timeout=240 Basic.sh * @run shell/timeout=240 Basic.sh

View file

@ -1792,6 +1792,15 @@ public class BasicBigDecimal extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicBigInteger extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicBoolean extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicBooleanObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicByte extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicByteObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicChar extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicCharObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicDateTime extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicDouble extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicDoubleObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicFloat extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicFloatObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicInt extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicIntObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicLong extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicLongObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicShort extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -1792,6 +1792,15 @@ public class BasicShortObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test("%%", "%", (Object)null); test("%%", "%", (Object)null);
test("%%", "%", ""); 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); tryCatch("%%%", UnknownFormatConversionException.class);
// perhaps an IllegalFormatArgumentIndexException should be defined? // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class); tryCatch("%<%", IllegalFormatFlagsException.class);

View file

@ -23,7 +23,7 @@
# questions. # questions.
# #
javac -d . ../../../../make/src/classes/build/tools/spp/Spp.java javac -d . ../../../../../make/jdk/src/classes/build/tools/spp/Spp.java
gen() { gen() {
# if [ $3 = "true" ] # if [ $3 = "true" ]