Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1439

FastDateParser throws NumberFormatException when parsing a long number based on a ISO8601 string

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.8.1
    • None
    • lang.time.*
    • None

    Description

      Given this piece of code:

          @Test
          public void testParseLongNumber() {
              final DateParser fdf = getInstance("yyyy-MM-dd'T'HH:mm:ssZZ");
              fdf.parse("999999999999"); // NFE here
          }
      

      Internally, the FastDateParser.NumberStrategy::parse method parses the year from that number (without maxWidth because the next part is not a number) using Integer::parseInt thus leading to a NumberFormatException.

      A quick fix for this would be catching the NFE then return false after setting the error position so that the FastDateParse::Parse method can throw a ParseException correctly.

      Edit: the suggested patch is attached below

      Attachments

        1. suggested-fix.patch
          2 kB
          Nghia Nguyen

        Issue Links

          Activity

            People

              Unassigned Unassigned
              foly Nghia Nguyen
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: