From ae765dfc327c5b3da48da268e868918d2e25cd06 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 25 Oct 2013 07:15:26 +0200 Subject: [PATCH] Remove some impossible-to-trigger code. --- .../net/pterodactylus/sone/core/SoneParser.java | 34 +++++++--------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/SoneParser.java b/src/main/java/net/pterodactylus/sone/core/SoneParser.java index 5a7229d..7eea4cc 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneParser.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneParser.java @@ -85,16 +85,11 @@ public class SoneParser { throw new InvalidXml(); } - Optional soneXml = parseXml(document); - if (!soneXml.isPresent()) { - logger.log(Level.WARNING, String.format("XML for Sone %s can not be parsed!", originalSone.getId())); - throw new InvalidXml(); - } - - Optional parsedClient = parseClient(originalSone, soneXml.get()); + SimpleXML soneXml = SimpleXML.fromDocument(document); + Optional parsedClient = parseClient(originalSone, soneXml); Sone sone = new DefaultSone(database, originalSone.getId(), originalSone.isLocal(), parsedClient.or(originalSone.getClient())); - Optional protocolVersion = parseProtocolVersion(soneXml.get()); + Optional protocolVersion = parseProtocolVersion(soneXml); if (protocolVersion.isPresent()) { if (protocolVersion.get() < 0) { logger.log(Level.WARNING, String.format("Invalid protocol version: %d! Not parsing Sone.", protocolVersion.get())); @@ -106,7 +101,7 @@ public class SoneParser { } } - String soneTime = soneXml.get().getValue("time", null); + String soneTime = soneXml.getValue("time", null); if (soneTime == null) { /* TODO - mark Sone as bad. */ logger.log(Level.WARNING, String.format("Downloaded time for Sone %s was null!", sone)); @@ -120,7 +115,7 @@ public class SoneParser { throw new MalformedTime(); } - SimpleXML profileXml = soneXml.get().getNode("profile"); + SimpleXML profileXml = soneXml.getNode("profile"); if (profileXml == null) { /* TODO - mark Sone as bad. */ logger.log(Level.WARNING, String.format("Downloaded Sone %s has no profile!", sone)); @@ -159,7 +154,7 @@ public class SoneParser { } /* parse posts. */ - SimpleXML postsXml = soneXml.get().getNode("posts"); + SimpleXML postsXml = soneXml.getNode("posts"); Set posts = new HashSet(); if (postsXml == null) { /* TODO - mark Sone as bad. */ @@ -192,7 +187,7 @@ public class SoneParser { } /* parse replies. */ - SimpleXML repliesXml = soneXml.get().getNode("replies"); + SimpleXML repliesXml = soneXml.getNode("replies"); Set replies = new HashSet(); if (repliesXml == null) { /* TODO - mark Sone as bad. */ @@ -221,7 +216,7 @@ public class SoneParser { } /* parse liked post IDs. */ - SimpleXML likePostIdsXml = soneXml.get().getNode("post-likes"); + SimpleXML likePostIdsXml = soneXml.getNode("post-likes"); Set likedPostIds = new HashSet(); if (likePostIdsXml == null) { /* TODO - mark Sone as bad. */ @@ -234,7 +229,7 @@ public class SoneParser { } /* parse liked reply IDs. */ - SimpleXML likeReplyIdsXml = soneXml.get().getNode("reply-likes"); + SimpleXML likeReplyIdsXml = soneXml.getNode("reply-likes"); Set likedReplyIds = new HashSet(); if (likeReplyIdsXml == null) { /* TODO - mark Sone as bad. */ @@ -247,7 +242,7 @@ public class SoneParser { } /* parse albums. */ - SimpleXML albumsXml = soneXml.get().getNode("albums"); + SimpleXML albumsXml = soneXml.getNode("albums"); Map albums = Maps.newHashMap(); if (albumsXml != null) { for (SimpleXML albumXml : albumsXml.getNodes("album")) { @@ -321,15 +316,6 @@ public class SoneParser { return fromNullable(Ints.tryParse(soneProtocolVersion)); } - private Optional parseXml(Document document) { - try { - return fromNullable(SimpleXML.fromDocument(document)); - } catch (NullPointerException npe1) { - /* for some reason, invalid XML can cause NPEs. */ - return absent(); - } - } - private Optional parseClient(Sone sone, SimpleXML soneXml) { SimpleXML clientXml = soneXml.getNode("client"); if (clientXml == null) { -- 2.7.4