commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters DateLocaleConverter.java
Date Sun, 15 Feb 2004 11:59:55 GMT
rdonkin     2004/02/15 03:59:55

  Modified:    beanutils/src/java/org/apache/commons/beanutils/locale/converters
                        DateLocaleConverter.java
  Log:
  Fixed issue with multithreaded access to single SimpleDateFormat instance. Thanks to Luca
Masini for spotting this one and for suggestion the optimal way to solve it.
  
  Revision  Changes    Path
  1.8       +10 -10    jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverter.java
  
  Index: DateLocaleConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverter.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DateLocaleConverter.java	9 Oct 2003 20:41:41 -0000	1.7
  +++ DateLocaleConverter.java	15 Feb 2004 11:59:55 -0000	1.8
  @@ -90,9 +90,8 @@
       /** All logging goes through this logger */
       private static Log log = LogFactory.getLog(DateLocaleConverter.class);
   
  -    /** The Date formatter */
  -    private SimpleDateFormat formatter = getPattern(pattern, locale);
  -
  +    /** Should the date conversion be lenient? */
  +    boolean isLenient = false;
   
       // ----------------------------------------------------------- Constructors
   
  @@ -268,7 +267,7 @@
        * @see java.text.DateFormat#isLenient
        */
       public boolean isLenient() {
  -        return formatter.isLenient();
  +        return isLenient;
       }
       
       /**
  @@ -278,7 +277,7 @@
        * @see java.text.DateFormat#setLenient
        */
       public void setLenient(boolean lenient) {
  -        formatter.setLenient(lenient);
  +        isLenient = lenient;
       }	
   
       // --------------------------------------------------------- Methods
  @@ -294,6 +293,7 @@
        *  successfully
        */
       protected Object parse(Object value, String pattern) throws ParseException {
  +        SimpleDateFormat formatter = getFormatter(pattern, locale);
           if (locPattern) {
               formatter.applyLocalizedPattern(pattern);
           }
  @@ -307,7 +307,7 @@
        * Gets an appropriate <code>SimpleDateFormat</code> for given locale,

        * default Date format pattern is not provided.
        */
  -    private SimpleDateFormat getPattern(String pattern, Locale locale) {
  +    private SimpleDateFormat getFormatter(String pattern, Locale locale) {
           // This method is a fix for null pattern, which would cause 
           // Null pointer exception when applied
           // Note: that many constructors default the pattern to null, 
  @@ -318,7 +318,7 @@
               log.warn("Null pattern was provided, defaulting to: " + pattern);
           }
           SimpleDateFormat format = new SimpleDateFormat(pattern, locale);
  -        format.setLenient(false);
  +        format.setLenient(isLenient);
           return format;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message