Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-486

DateConverter fails when pattern and locale are set

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.9.2
    • None
    • MacOS X 10.11.4
      Java 1.8.0_11
      Default locale: de_DE

    Description

      When using a DateConverter or any of the date conversion classes, setting an explicit pattern causes the locale to be ignored. The converter seems to think that the locale is only useful for finding the default pattern for the locale, but that's not true, as the following code illustrates.

          public static void main(String[] args) {
              SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy", new Locale("en_US"));
              ParsePosition pos = new ParsePosition(0);
              Date result = sdf.parse("Dec 15, 1978", pos);
              System.out.println(result); // Prints "Fri Dec 15 00:00:00 CET 1978"
              
              // Equivalent code should return the same result as the last section
              DateConverter c = new DateConverter();
              c.setPattern("MMM dd, yyyy");
              c.setLocale(new Locale("en_US"));
              c.convert(Date.class, "Dec 15, 1978"); // Throws ConversionException
          }
      

      I'm expanding opencsv (opencsv.sourceforge.net), and this bug is breaking my code. I would really appreciate a speedy resolution.

      Attachments

        Activity

          People

            Unassigned Unassigned
            arjones Andrew Rucker Jones
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: