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

DateUtils.parseDateWithLeniency() doesn't accept "GMT" as "zzz" timezone on Android

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.14.0
    • None
    • lang.time.*
    • None
    • Not working: Android 14 (API 34) phone and emulator, Android 12 (API 31) emulator

      Working: Arch Linux OpenJDK 11

    Description

      Commons Lang3 3.14.0 DateUtils, i.e. FastDateParser under the hood, doesn't accept "GMT" as a valid timezone for "zzz" on Android 14, but does accept it on desktop OpenJDK 11.

      For example, the string "Mon, 01 May 2023 08:52:19 GMT" can't be parsed with pattern "EEE, dd MMM yyyy HH:mm:ss zzz" on Android.

      The same issue was reported at https://github.com/bitfireAT/dav4jvm/issues/22 , but I found that it's also not working on Android 12 emulator, so I believe the actual cause is Commons Lang3 using FastDateParser v.s. previously using SimpleDateFormat, instead of upgraded Android platform version.

      I debugged this a little bit and found that the generated regex in FastDateParser.TimeZoneStrategy doesn't contain "|gmt|" on Android 14, but does contain "|gmt|" on desktop. I suspect maybe Android has some different timezone info. I also saw the intentional skip for `TimeZones.GMT_ID` in FastDateParser code, which makes me wonder how it got the "|gmt|" on desktop.

      Here are the different generated regexes I saw, with unrelated timezones replaced with "...":

      ```
      ((?iu)[+-]\d

      {4}|GMT[+-]\d{1,2}:\d{2}|yukon time|...|gulf standard time|greenwich mean time|gmt-12:00|gmt-11:00|gmt-10:00|gmt-09:30|gmt-09:00|gmt-08:00|gmt-07:00|gmt-06:00|gmt-05:00|gmt-04:00|gmt-03:30|gmt-03:00|gmt-02:30|gmt-02:00|gmt-01:00|gmt+14:00|gmt+13:45|gmt+13:00|gmt+12:45|gmt+12:00|gmt+11:00|gmt+10:30|gmt+10:00|gmt+09:30|gmt+09:00|gmt+08:45|gmt+08:00|gmt+07:00|gmt+06:30|gmt+06:00|gmt+05:45|gmt+05:30|gmt+05:00|gmt+04:30|gmt+04:00|gmt+03:30|gmt+03:00|gmt+02:00|gmt+01:00|gmt+00:00|gilbert islands time|...|acre standard time)
      ```

      ```
      ((?iu)[+-]\d{4}

      |GMT[+-]\d

      {1,2}

      :\d

      {2}

      |yekt|...|gulf daylight time|gt|gst|greenwich mean time|gmt-12:00|gmt-11:00|gmt-10:00|gmt-09:00|gmt-08:00|gmt-07:00|gmt-06:00|gmt-05:00|gmt-04:00|gmt-03:00|gmt-02:00|gmt-01:00|gmt+14:00|gmt+13:00|gmt+12:00|gmt+11:00|gmt+10:00|gmt+09:00|gmt+08:00|gmt+07:00|gmt+06:00|gmt+05:00|gmt+04:00|gmt+03:00|gmt+02:00|gmt+01:00|gmt|gilt|....|acre standard time|acdt)
      ```

      Attachments

        Activity

          People

            Unassigned Unassigned
            dreamingincode Hai Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: