From d1cf9cd9719341f1a69ae075c5fbbde441f63875 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Thu, 8 Dec 2005 21:12:25 +0000 Subject: [PATCH] Fixed concurrency issue with date formatter. SMACK-111 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3180 b35dd754-fafc-0310-a699-88a17e54d16e --- .../jivesoftware/smackx/packet/DelayInformation.java | 6 +++++- .../smackx/provider/DelayInformationProvider.java | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/source/org/jivesoftware/smackx/packet/DelayInformation.java b/source/org/jivesoftware/smackx/packet/DelayInformation.java index e9e90331a..c04409b3a 100644 --- a/source/org/jivesoftware/smackx/packet/DelayInformation.java +++ b/source/org/jivesoftware/smackx/packet/DelayInformation.java @@ -127,7 +127,11 @@ public class DelayInformation implements PacketExtension { StringBuffer buf = new StringBuffer(); buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append( "\""); - buf.append(" stamp=\"").append(UTC_FORMAT.format(stamp)).append("\""); + buf.append(" stamp=\""); + synchronized (UTC_FORMAT) { + buf.append(UTC_FORMAT.format(stamp)); + } + buf.append("\""); if (from != null && from.length() > 0) { buf.append(" from=\"").append(from).append("\""); } diff --git a/source/org/jivesoftware/smackx/provider/DelayInformationProvider.java b/source/org/jivesoftware/smackx/provider/DelayInformationProvider.java index 2065af6fe..28bab2367 100644 --- a/source/org/jivesoftware/smackx/provider/DelayInformationProvider.java +++ b/source/org/jivesoftware/smackx/provider/DelayInformationProvider.java @@ -48,13 +48,17 @@ public class DelayInformationProvider implements PacketExtensionProvider { public PacketExtension parseExtension(XmlPullParser parser) throws Exception { Date stamp = null; try { - stamp = DelayInformation.UTC_FORMAT.parse(parser.getAttributeValue("", "stamp")); + synchronized (DelayInformation.UTC_FORMAT) { + stamp = DelayInformation.UTC_FORMAT.parse(parser.getAttributeValue("", "stamp")); + } } catch (ParseException e) { // Try again but assuming that the date follows JEP-82 format // (Jabber Date and Time Profiles) try { - stamp = DelayInformation.NEW_UTC_FORMAT - .parse(parser.getAttributeValue("", "stamp")); + synchronized (DelayInformation.NEW_UTC_FORMAT) { + stamp = DelayInformation.NEW_UTC_FORMAT + .parse(parser.getAttributeValue("", "stamp")); + } } catch (ParseException e1) { // Last attempt. Try parsing the date assuming that it does not include milliseconds SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");