GeoJSONUtil incorrectly shares a SimpleDateFormat static instance

Description

The class org.geotools.geojson.GeoJSONUtil is using a shared static instance of SimpleDateFormat

);
{
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone());
}

As documented in the class javadoc, use of it not thread-safe:

<blockquote>Synchronization - 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.</blockquote>

Invocation of org.geotools.geojson.GeoJSONUtil.entry() in a multi-threaded environment causes the SimpleDateFormat to break with a ArrayOutOfBounds runtime exception, with a stakctrace like the following:

2015-02-26_05:32:01.90536 Exception in thread "Thread-45" java.lang.ArrayIndexOutOfBoundsException: 14
2015-02-26_05:32:01.90612 at sun.util.calendar.BaseCalendar.getCalendarDateFromFixedDate(BaseCalendar.java:454)
2015-02-26_05:32:01.90613 at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:2333)
2015-02-26_05:32:01.90613 at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:2248)
2015-02-26_05:32:01.90613 at java.util.Calendar.complete(Calendar.java:1560)
2015-02-26_05:32:01.90614 at java.util.Calendar.get(Calendar.java:1162)
2015-02-26_05:32:01.90614 at java.text.SimpleDateFormat.subFormat(SimpleDateFormat.java:1093)
2015-02-26_05:32:01.90614 at java.text.SimpleDateFormat.format(SimpleDateFormat.java:978)
2015-02-26_05:32:01.90615 at java.text.SimpleDateFormat.format(SimpleDateFormat.java:948)
2015-02-26_05:32:01.90615 at java.text.DateFormat.format(DateFormat.java:336)
2015-02-26_05:32:01.90615 at org.geotools.geojson.GeoJSONUtil.literal(GeoJSONUtil.java:178)
2015-02-26_05:32:01.90615 at org.geotools.geojson.GeoJSONUtil.entry(GeoJSONUtil.java:163)

Environment

None

Assignee

Unassigned

Reporter

codehaus

Triage

None

Components

Affects versions

Priority

Medium
Configure