From 2d3caec6e09b80daa4721f20c92113862f2164a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 21 Oct 2010 10:46:05 +0200 Subject: [PATCH] XML parsing is not thread-safe, synchronize on Sone downloader. --- src/main/java/net/pterodactylus/sone/core/SoneDownloader.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index e11ded8..4469d2f 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -150,7 +150,16 @@ public class SoneDownloader extends AbstractService { try { xmlBucket = fetchResult.asBucket(); xmlInputStream = xmlBucket.getInputStream(); - Document document = XML.transformToDocument(xmlInputStream); + Document document; + /* XML parsing is not thread-safe. */ + synchronized (this) { + document = XML.transformToDocument(xmlInputStream); + } + if (document == null) { + /* TODO - mark Sone as bad. */ + logger.log(Level.WARNING, "Could not parse XML for Sone %s at %s!", new Object[] { originalSone, requestUri }); + return null; + } SimpleXML soneXml; try { soneXml = SimpleXML.fromDocument(document); -- 2.7.4