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(NumberFormatException.java:48)
at java.lang.Long.parseLong(Long.java:424)
at java.lang.Long.parseLong(Long.java:461)
at java.text.DigitList.getLong(DigitList.java:177)
at java.text.DecimalFormat.parse(DecimalFormat.java:1298)
at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1536)
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1263)
at java.text.DateFormat.parse(DateFormat.java:335)
at org.jivesoftware.smackx.workgroup.packet.QueueDetails$Provider.parseExtension(Q ueueDetails.java:174)
at org.jivesoftware.smack.util.PacketParserUtils.parsePacketExtension(PacketParser Utils.java:378)
at org.jivesoftware.smack.util.PacketParserUtils.parsePresence(PacketParserUtils.j ava:204)
at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:278)
at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:76)