Uploaded image for project: 'Sakai'
  1. Sakai
  2. SAK-22622

Sakai News won't work in some locale

    XMLWordPrintable

    Details

    • 2.9 Status:
      Resolved

      Description

      Reproduce the bug:
      1.Use zh_CN as default language by setting "-Duser.language=zh -Duser.region=CN".
      2.Add a news tool to some site and use the default "http://sakaiproject.org/feed"
      3.Go to the news tool and get the error message in news-error.png
      Reason:
      Sakai news tool uses a deprecated api "new Date(String)" to convert a string to date. The string was created by "DateFormat.getDateInstance().format(String)", and this will generate some string that "new Date(String)" won't handle (zh_CN for example, which generate a String like 2012-9-17). The following code can show the difference:

      String dateUS = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.US).format(new Date());
      String dateChina = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.CHINA).format(new Date());
      System.out.println(String.format("dateUS: %s, dateChina: %s", dateUS, dateChina));
      System.out.println(new Date(dateUS));
      System.out.println(new Date(dateChina)); // <-- This will get an IllegalArgumentException

      Solution:
      Since "new Date(String)" is a deprecated API, it's better to replace it with DateFormat.getInstance().parse(String)". This API works fine.

      Patch:
      news.patch

        Gliffy Diagrams

          Attachments

          1. news.patch
            2 kB
          2. news-error.png
            news-error.png
            113 kB

            Activity

              People

              • Assignee:
                steve.swinsburg Steve Swinsburg
                Reporter:
                gaojun Gao Jun
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Git Source Code