5063507: (fmt) missing exception for "%#s" format specifier
Summary: throw appropriate exception when necessary
Reviewed-by: alanb
--- a/jdk/src/share/classes/java/util/Formatter.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/src/share/classes/java/util/Formatter.java Fri Jul 24 11:06:57 2009 -0700
@@ -2818,15 +2818,18 @@
}
private void printString(Object arg, Locale l) throws IOException {
- if (arg == null) {
- print("null");
- } else if (arg instanceof Formattable) {
+ if (arg instanceof Formattable) {
Formatter fmt = formatter;
if (formatter.locale() != l)
fmt = new Formatter(formatter.out(), l);
((Formattable)arg).formatTo(fmt, f.valueOf(), width, precision);
} else {
- print(arg.toString());
+ if (f.contains(Flags.ALTERNATE))
+ failMismatch(Flags.ALTERNATE, 's');
+ if (arg == null)
+ print("null");
+ else
+ print(arg.toString());
}
}
--- a/jdk/test/java/util/Formatter/Basic-X.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/Basic-X.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/Basic.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/Basic.java Fri Jul 24 11:06:57 2009 -0700
@@ -25,7 +25,7 @@
* @summary Unit test for formatter
* @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
+ * 6344623 6369500 6534606 6282094 6286592 6476425 5063507
*
* @run shell/timeout=240 Basic.sh
*/
--- a/jdk/test/java/util/Formatter/BasicBigDecimal.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicBigDecimal.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicBigInteger.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicBigInteger.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicBoolean.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicBoolean.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicBooleanObject.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicBooleanObject.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicByte.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicByte.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicByteObject.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicByteObject.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicChar.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicChar.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicCharObject.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicCharObject.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicDateTime.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicDateTime.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicDouble.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicDouble.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicDoubleObject.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicDoubleObject.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicFloat.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicFloat.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicFloatObject.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicFloatObject.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicInt.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicInt.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicIntObject.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicIntObject.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicLong.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicLong.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicLongObject.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicLongObject.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicShort.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicShort.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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
--- a/jdk/test/java/util/Formatter/BasicShortObject.java Thu Jul 23 14:06:51 2009 +0100
+++ b/jdk/test/java/util/Formatter/BasicShortObject.java Fri Jul 24 11:06:57 2009 -0700
@@ -486,6 +486,10 @@
//---------------------------------------------------------------------
tryCatch("%-s", MissingFormatWidthException.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