XML parsing is not thread-safe, synchronize on Sone downloader.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 21 Oct 2010 08:46:05 +0000 (10:46 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 21 Oct 2010 08:46:05 +0000 (10:46 +0200)
src/main/java/net/pterodactylus/sone/core/SoneDownloader.java

index e11ded8..4469d2f 100644 (file)
@@ -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);