提交 1b55cb24 编写于 作者: S sherman

5063507: (fmt) missing exception for "%#s" format specifier

Summary: throw appropriate exception when necessary
Reviewed-by: alanb
上级 ee04cdf5
...@@ -2818,15 +2818,18 @@ public final class Formatter implements Closeable, Flushable { ...@@ -2818,15 +2818,18 @@ public final class Formatter implements Closeable, Flushable {
} }
private void printString(Object arg, Locale l) throws IOException { private void printString(Object arg, Locale l) throws IOException {
if (arg == null) { if (arg instanceof Formattable) {
print("null");
} else if (arg instanceof Formattable) {
Formatter fmt = formatter; Formatter fmt = formatter;
if (formatter.locale() != l) if (formatter.locale() != l)
fmt = new Formatter(formatter.out(), l); fmt = new Formatter(formatter.out(), l);
((Formattable)arg).formatTo(fmt, f.valueOf(), width, precision); ((Formattable)arg).formatTo(fmt, f.valueOf(), width, precision);
} else { } else {
print(arg.toString()); if (f.contains(Flags.ALTERNATE))
failMismatch(Flags.ALTERNATE, 's');
if (arg == null)
print("null");
else
print(arg.toString());
} }
} }
......
...@@ -486,6 +486,10 @@ public class Basic$Type$ extends Basic { ...@@ -486,6 +486,10 @@ public class Basic$Type$ extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* @summary Unit test for formatter * @summary Unit test for formatter
* @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 * 6344623 6369500 6534606 6282094 6286592 6476425 5063507
* *
* @run shell/timeout=240 Basic.sh * @run shell/timeout=240 Basic.sh
*/ */
......
...@@ -486,6 +486,10 @@ public class BasicBigDecimal extends Basic { ...@@ -486,6 +486,10 @@ public class BasicBigDecimal extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicBigInteger extends Basic { ...@@ -486,6 +486,10 @@ public class BasicBigInteger extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicBoolean extends Basic { ...@@ -486,6 +486,10 @@ public class BasicBoolean extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicBooleanObject extends Basic { ...@@ -486,6 +486,10 @@ public class BasicBooleanObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicByte extends Basic { ...@@ -486,6 +486,10 @@ public class BasicByte extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicByteObject extends Basic { ...@@ -486,6 +486,10 @@ public class BasicByteObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicChar extends Basic { ...@@ -486,6 +486,10 @@ public class BasicChar extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicCharObject extends Basic { ...@@ -486,6 +486,10 @@ public class BasicCharObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicDateTime extends Basic { ...@@ -486,6 +486,10 @@ public class BasicDateTime extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicDouble extends Basic { ...@@ -486,6 +486,10 @@ public class BasicDouble extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicDoubleObject extends Basic { ...@@ -486,6 +486,10 @@ public class BasicDoubleObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicFloat extends Basic { ...@@ -486,6 +486,10 @@ public class BasicFloat extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicFloatObject extends Basic { ...@@ -486,6 +486,10 @@ public class BasicFloatObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicInt extends Basic { ...@@ -486,6 +486,10 @@ public class BasicInt extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicIntObject extends Basic { ...@@ -486,6 +486,10 @@ public class BasicIntObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicLong extends Basic { ...@@ -486,6 +486,10 @@ public class BasicLong extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicLongObject extends Basic { ...@@ -486,6 +486,10 @@ public class BasicLongObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicShort extends Basic { ...@@ -486,6 +486,10 @@ public class BasicShort extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
...@@ -486,6 +486,10 @@ public class BasicShortObject extends Basic { ...@@ -486,6 +486,10 @@ public class BasicShortObject extends Basic {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.class); tryCatch("%-s", MissingFormatWidthException.class);
tryCatch("%--s", DuplicateFormatFlagsException.class); tryCatch("%--s", DuplicateFormatFlagsException.class);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// %h // %h
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册