@@ -0,0 +1,2892 @@
+/*%0A *    GeoTools - The Open Source Java GIS Toolkit%0A *    http://geotools.org%0A *%0A *    (C) 2002-2010, Open Source Geospatial Foundation (OSGeo)%0A *%0A *    This library is free software; you can redistribute it and/or%0A *    modify it under the terms of the GNU Lesser General Public%0A *    License as published by the Free Software Foundation;%0A *    version 2.1 of the License.%0A *%0A *    This library is distributed in the hope that it will be useful,%0A *    but WITHOUT ANY WARRANTY; without even the implied warranty of%0A *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A *    Lesser General Public License for more details.%0A */%0Apackage org.geotools.geojson;%0A%0Aimport java.io.IOException;%0Aimport java.io.StringReader;%0Aimport java.lang.StringBuilder;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.Date;%0Aimport java.util.List;%0Aimport java.util.ArrayList;%0Aimport java.util.Map;%0Aimport java.util.HashMap;%0Aimport java.util.TimeZone;%0Aimport java.util.concurrent.Callable;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.Future;%0Aimport java.util.Random;%0A%0Aimport junit.framework.TestCase;%0A%0A/**%0A * Exploit bug GEOT-5036, concurrent use of GeoJSONUtil.%0A * @author Guido Grazioli %3Cguido.grazioli@gmail.com%3E%0A *%0A */%0Apublic class GEOT5036RegressionTest extends TestCase %7B%0A%0A    private Random rand = new Random();%0A    private Map%3CDate, Future%3CString%3E%3E expectationMap = new HashMap%3CDate, Future%3CString%3E%3E();%0A%0A    public class Task implements Callable%3CString%3E %7B%0A        private final Date date;%0A%0A        public Task(Date d) %7B%0A            this.date = d;%0A        %7D%0A%0A        public String call() throws Exception %7B%0A            StringBuilder sb = new StringBuilder();%0A            GeoJSONUtil.literal(date, sb);%0A            return sb.toString();%0A        %7D%0A    %7D%0A%0A    public void setUp() throws java.lang.Exception %7B%0A        SimpleDateFormat sdf = GeoJSONUtil.DATE_FORMAT;%0A        // perform 50 conversions%0A        for (int i = 0; i %3C 50; i++) %7B%0A            Date date = new Date(System.currentTimeMillis() - rand.nextInt(100) * 1000 * 3600 * 24);%0A            expectationMap.put(date, null);%0A        %7D%0A    %7D%0A    %0A    public void testDateFormatterResults() throws Exception %7B%0A        SimpleDateFormat sdf = GeoJSONUtil.DATE_FORMAT;%0A%0A        // pool with 8 threads%0A        ExecutorService exec = Executors.newFixedThreadPool(8);%0A%0A        // perform date conversions%0A        for (Date key : expectationMap.keySet()) %7B%0A            Task task = new Task(key);%0A            expectationMap.put(key, exec.submit(task));%0A        %7D%0A        exec.shutdown();%0A%0A        // look at the results%0A        for (Map.Entry%3CDate, Future%3CString%3E%3E entry : expectationMap.entrySet()) %7B%0A            assertEquals(%22incorrect date string was returned: %22, entry.getValue().get(),%0A                    %22%5C%22%22 + sdf.format(entry.getKey()) + %22%5C%22%22);%0A        %7D%0A    %7D%0A%0A%7D%0A

Add regression test for bug GEOT-5036