Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8012691

IntSummaryStatistics, LongSummaryStatistics: toString() fails with java.util.IllegalFormatConversionException

XMLWordPrintable

      Let's consider following code:

      import java.util.IntSummaryStatistics;

      public class IntSummStatsTest {
          public static void main(String[] asrt) {
              new IntSummaryStatistics().toString();
          }
      }

      Its running causes following output:

      Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
      at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4309)
      at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2774)
      at java.util.Formatter$FormatSpecifier.print(Formatter.java:2728)
      at java.util.Formatter.format(Formatter.java:2514)
      at java.util.Formatter.format(Formatter.java:2449)
      at java.lang.String.format(String.java:2907)
      at java.util.IntSummaryStatistics.toString(IntSummaryStatistics.java:154)
      at IntSummStatsTest.main(IntSummStatsTest.java:5)

      The same thing happens to LongStreamStatistics:

      import java.util.LongSummaryStatistics;

      public class LongSummStatsTest {
          public static void main(String[] asrt) {
              new LongSummaryStatistics().toString();
          }
      }

      the code above leads to:

      Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
      at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4309)
      at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2774)
      at java.util.Formatter$FormatSpecifier.print(Formatter.java:2728)
      at java.util.Formatter.format(Formatter.java:2514)
      at java.util.Formatter.format(Formatter.java:2449)
      at java.lang.String.format(String.java:2907)
      at java.util.LongSummaryStatistics.toString(LongSummaryStatistics.java:166)
      at LongSummStatsTest.main(LongSummStatsTest.java:5)

      The code is attached for your convenience.

        1. IntSummStatsTest.java
          0.2 kB
          Georgiy Rakov
        2. LongSummStatsTest.java
          0.2 kB
          Georgiy Rakov

            mduigou Mike Duigou
            grakov Georgiy Rakov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: