Smack use SimpleDateFormat is not thread safe

Smack use SimpleDateFormat is not thread safe.

I recently tested for workgroup extension. I use smack write client for many webchat and agent, and throw java.lang.NumberFormatException: For input string: “”

in javadoc, java.text.SimpleDateFormat:

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.

But some places in smack, it use SimpleDateFormat as a static field for all parse and format in this class, and not synchronized, eg. org.jivesoftware.smackx.workgroup.packet.QueueDetails:

private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat(“yyyyMMdd’T’HH:mm:ss”);

So, if multi thread conditions, it cause :

java.lang.NumberFormatException: For input string: “”

at java.lang.NumberFormatException.forInputString(

at java.lang.Long.parseLong(

at java.lang.Long.parseLong(

at java.text.DigitList.getLong(

at java.text.DecimalFormat.parse(

at java.text.SimpleDateFormat.subParse(

at java.text.SimpleDateFormat.parse(

at java.text.DateFormat.parse(

at org.jivesoftware.smackx.workgroup.packet.QueueDetails$Provider.parseExtension(Q

at org.jivesoftware.smack.util.PacketParserUtils.parsePacketExtension(PacketParser

at org.jivesoftware.smack.util.PacketParserUtils.parsePresence(PacketParserUtils.j ava:204)

at org.jivesoftware.smack.PacketReader.parsePackets(

at org.jivesoftware.smack.PacketReader.access$000(

at org.jivesoftware.smack.PacketReader$

Logged as SMACK-321

The format Method is not thread safe. Try joda datetime ( it is thread safe and easy to use.

Duplicate and already fixed as SMACK-328.