The following program illustrates an assertion error in Formatter.
==========$ cat -n T.java
1 class T {
2 public static void main(String[] args) {
3 System.out.printf("%9999999999d%n", 12);
4 }
5 }
==========$ javac T.java
==========$ java -esa T
Exception in thread "main" java.lang.AssertionError
at java.util.Formatter$FormatSpecifier.width(Formatter.java:2479)
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2527)
at java.util.Formatter.parse(Formatter.java:2389)
at java.util.Formatter.format(Formatter.java:2323)
at java.io.PrintStream.format(PrintStream.java:908)
at java.io.PrintStream.printf(PrintStream.java:809)
at T.main(T.java:3)
==========$
This is critical for Tiger because fixing it requires an API change.
Specifically, in this case we have an illegal width, but the state of
the class IllegalFormatWidthException, which is required by specification
to be thrown in this case, is an int instead of a String.
The illegal width cannot be expressed in an int, so it is not possible
for the required exception with the specified state to be created.
In general, the illegal width can be an arbitrary string of digits.
A similar issue arises for IllegalFormatPrecisionException. Unless this
is fixed in Tiger we will have a specification that is impossible to
correctly implement.
###@###.### 2004-06-07
==========$ cat -n T.java
1 class T {
2 public static void main(String[] args) {
3 System.out.printf("%9999999999d%n", 12);
4 }
5 }
==========$ javac T.java
==========$ java -esa T
Exception in thread "main" java.lang.AssertionError
at java.util.Formatter$FormatSpecifier.width(Formatter.java:2479)
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2527)
at java.util.Formatter.parse(Formatter.java:2389)
at java.util.Formatter.format(Formatter.java:2323)
at java.io.PrintStream.format(PrintStream.java:908)
at java.io.PrintStream.printf(PrintStream.java:809)
at T.main(T.java:3)
==========$
This is critical for Tiger because fixing it requires an API change.
Specifically, in this case we have an illegal width, but the state of
the class IllegalFormatWidthException, which is required by specification
to be thrown in this case, is an int instead of a String.
The illegal width cannot be expressed in an int, so it is not possible
for the required exception with the specified state to be created.
In general, the illegal width can be an arbitrary string of digits.
A similar issue arises for IllegalFormatPrecisionException. Unless this
is fixed in Tiger we will have a specification that is impossible to
correctly implement.
###@###.### 2004-06-07
- duplicates
-
JDK-8253459 Formatter treats index, width and precision > Integer.MAX_VALUE incorrectly
-
- Closed
-