From 0d70f76a105c77eb8da1aed67764b725a91335f4 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Mon, 28 Jan 2013 16:40:08 +0100 Subject: [PATCH] Fix crash caused by a cast error (creationtime field can be an Integer or a Long, depending on the used dialect). --- .../daemon/Rtorrent/RtorrentAdapter.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java b/lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java index 10c58952..23aa0631 100644 --- a/lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java +++ b/lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java @@ -288,15 +288,24 @@ public class RtorrentAdapter implements IDaemonAdapter { String error = (String)info[18]; error = error.equals("")? null: error; + // Determine the time added Date added = null; - Date finished = null; if(!((String)info[19]).equals("")) - added = new Date(Long.valueOf(((String)info[19]).trim())); - else - added = new Date((Long)info[11]); + // Successfully received the addtime from rTorrent (which is a String like '1337089336\n') + added = new Date(Long.valueOf(((String)info[19]).trim()) * 1000L); + else { + // rTorrent didn't have the addtime (missing plugin?): base it on creationtime instead + if (info[11] instanceof Long) + added = new Date((Long)info[11] * 1000L); + else + added = new Date((Integer)info[11] * 1000L); + } + // Determine the seeding time + Date finished = null; if(!((String)info[20]).equals("")) - finished = new Date(Long.valueOf(((String)info[20]).trim())); + // Successfully received the seedingtime from rTorrent (which is a String like '1337089336\n') + finished = new Date(Long.valueOf(((String)info[20]).trim()) * 1000L); String label = null;