From b8ac92a1ca0085609b3c2ebff16f4027ae9af858 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Sun, 17 Feb 2013 19:48:22 +0100 Subject: [PATCH] Prevent crash when Rtorrent does not return teh addtime or seedingtime custom fields (as timestamp). --- .../daemon/Rtorrent/RtorrentAdapter.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java b/lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java index 23aa0631..7e06af29 100644 --- a/lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java +++ b/lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java @@ -290,9 +290,15 @@ public class RtorrentAdapter implements IDaemonAdapter { // Determine the time added Date added = null; - if(!((String)info[19]).equals("")) + Long addtime = null; + try { + addtime = Long.valueOf(((String) info[19]).trim()); + } catch (NumberFormatException e) { + // Not a number (timestamp); ignore and fall back to using creationtime + } + if(addtime != null) // Successfully received the addtime from rTorrent (which is a String like '1337089336\n') - added = new Date(Long.valueOf(((String)info[19]).trim()) * 1000L); + added = new Date(addtime * 1000L); else { // rTorrent didn't have the addtime (missing plugin?): base it on creationtime instead if (info[11] instanceof Long) @@ -303,18 +309,22 @@ public class RtorrentAdapter implements IDaemonAdapter { // Determine the seeding time Date finished = null; - if(!((String)info[20]).equals("")) + Long seedingtime = null; + try { + seedingtime = Long.valueOf(((String) info[20]).trim()); + } catch (NumberFormatException e) { + // Not a number (timestamp); ignore and fall back to using creationtime + } + if(seedingtime != null) // Successfully received the seedingtime from rTorrent (which is a String like '1337089336\n') - finished = new Date(Long.valueOf(((String)info[20]).trim()) * 1000L); + finished = new Date(seedingtime * 1000L); + // Determine the label String label = null; - - try{ + try { label = URLDecoder.decode((String)info[21], "UTF-8"); + } catch (UnsupportedEncodingException e) { } - catch(UnsupportedEncodingException e){ - } - if (info[3] instanceof Long) {