[ 
https://issues.apache.org/struts/browse/WW-2567?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Don Brown updated WW-2567:
--------------------------

    Affects Version/s:     (was: 2.0.12)
                       2.0.11.1
        Fix Version/s: 2.0.12

> DateTimePicker makes non-thread-safe use of SimpleDateFormat
> ------------------------------------------------------------
>
>                 Key: WW-2567
>                 URL: https://issues.apache.org/struts/browse/WW-2567
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11.1
>            Reporter: Mike Calmus
>            Priority: Critical
>             Fix For: 2.0.12
>
>
> DateTimePicker has an internal static final instance of a SimpleDateFormat it 
> uses to format date strings.
> However, according to the SimpleDateFormat JavaDoc:
> Date formats are not synchronized. It is recommended to create separate 
> format instances for each thread. If multiple threads access a format 
> concurrently, it must be synchronized externally.
> Easy fix is to synchronize around all uses of the class.
> Index: src/main/java/org/apache/struts2/components/DateTimePicker.java
> ===================================================================
> --- src/main/java/org/apache/struts2/components/DateTimePicker.java     
> (revision 641326)
> +++ src/main/java/org/apache/struts2/components/DateTimePicker.java     
> (working copy)
> @@ -294,20 +294,25 @@
>              return null;
>          if(obj instanceof Date) {
> +          synchronized (RFC3339_FORMAT) {
>              return RFC3339_FORMAT.format((Date) obj);
> +          }
>          } else {
>              // try to parse a date
>              String dateStr = obj.toString();
>              if(dateStr.equalsIgnoreCase("today"))
> +              synchronized (RFC3339_FORMAT) {
>                  return RFC3339_FORMAT.format(new Date());
> -
> +              }
>              try {
>                  Date date = null;
>                  if(this.displayFormat != null) {
>                      SimpleDateFormat format = new SimpleDateFormat(
>                              (String) getParameters().get("displayFormat"));
>                      date = format.parse(dateStr);
> -                    return RFC3339_FORMAT.format(date);
> +                    synchronized (RFC3339_FORMAT) {
> +                      return RFC3339_FORMAT.format(date);
> +                    }
>                  } else {
>                      // last resource to assume already in correct/default 
> format
>                      return dateStr;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to