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

DateTimeFormatterBuilder throws ClassCastException when using padding

XMLWordPrintable

    • x86_64
    • linux

      FULL PRODUCT VERSION :
      Java 9: OpenJDK Runtime Environment (build 9.0.1+11)
      Java 10: Java(TM) SE Runtime Environment (build 10-ea+30)

      A DESCRIPTION OF THE PROBLEM :
      A ClassCastException is thrown from the internals of DateTimeFormatterBuilder when building a format using padding, e.g. DateTimeFormatter.ofPattern("pdQ");

      The exception message is: java.base/java.time.format.DateTimeFormatterBuilder$PadPrinterParserDecorator cannot be cast to java.base/java.time.format.DateTimeFormatterBuilder$NumberPrinterParser

      This bug was found using AFL + JQF.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the attached main class DateTimeFormatterTest


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.ClassCastException: java.base/java.time.format.DateTimeFormatterBuilder$PadPrinterParserDecorator cannot be cast to java.base/java.time.format.DateTimeFormatterBuilder$NumberPrinterParser
      at java.base/java.time.format.DateTimeFormatterBuilder.appendValue(DateTimeFormatterBuilder.java:636)
      at java.base/java.time.format.DateTimeFormatterBuilder.appendValue(DateTimeFormatterBuilder.java:394)
      at java.base/java.time.format.DateTimeFormatterBuilder.parseField(DateTimeFormatterBuilder.java:1876)
      at java.base/java.time.format.DateTimeFormatterBuilder.parsePattern(DateTimeFormatterBuilder.java:1723)
      at java.base/java.time.format.DateTimeFormatterBuilder.appendPattern(DateTimeFormatterBuilder.java:1691)
      at java.base/java.time.format.DateTimeFormatter.ofPattern(DateTimeFormatter.java:559)
      at DateTimeFormatterTest.main(DateTimeFormatterTest.java:5)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.time.format.DateTimeFormatter;

      public class DateTimeFormatterTest {
          public static void main(String args[]) {
              DateTimeFormatter.ofPattern("pdQ");
          }
      }

      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: