From d394dde36621a50c7200cc248aba0ccb4cfbf811 Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Mon, 22 Nov 2010 11:01:21 +0000 Subject: [PATCH] Fixes IndexOutOfBoundsException in Call History, prevents the gui from crashing in any exceptions coming from contact list filters and adds some logs in order to better analyze the situation, which provoked the exception in first place. --- .../callhistory/CallHistoryServiceImpl.java | 34 +++++++++++++++++-- .../impl/gui/main/call/OneToOneCallPanel.java | 1 - .../gui/main/contactlist/TreeContactList.java | 14 +++++++- .../history/records/HistoryRecord.java | 16 +++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java index 430b5da32..e9e54f84f 100644 --- a/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java +++ b/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java @@ -407,10 +407,40 @@ else if(propName.equals(STRUCTURE_NAMES[8])) final int callPeerCount = callPeerIDs == null ? 0 : callPeerIDs.size(); for (int i = 0; i < callPeerCount; i++) { + // As we iterate over the CallPeer IDs we could not be sure that + // for some reason the start or end call list could result in + // different size lists, so we check this first. + Date callPeerStartValue = null; + Date callPeerEndValue = null; + + if (i < callPeerStart.size()) + { + callPeerStartValue + = new Date(Long.parseLong(callPeerStart.get(i))); + } + else + { + callPeerStartValue = result.getStartTime(); + if (logger.isTraceEnabled()) + logger.trace( + "Call history start time list different from ids list: " + + hr.toString()); + } + + if (i < callPeerEnd.size()) + { + callPeerEndValue + = new Date(Long.parseLong(callPeerEnd.get(i))); + } + else + { + callPeerEndValue = result.getEndTime(); + } + CallPeerRecordImpl cpr = new CallPeerRecordImpl(callPeerIDs.get(i), - new Date(Long.parseLong(callPeerStart.get(i))), - new Date(Long.parseLong(callPeerEnd.get(i)))); + callPeerStartValue, + callPeerEndValue); // if there is no record about the states (backward compability) if (callPeerStates != null) diff --git a/src/net/java/sip/communicator/impl/gui/main/call/OneToOneCallPanel.java b/src/net/java/sip/communicator/impl/gui/main/call/OneToOneCallPanel.java index bd44f7feb..ea2597cfd 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/OneToOneCallPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/OneToOneCallPanel.java @@ -9,7 +9,6 @@ import java.awt.event.*; import javax.swing.*; -import javax.swing.event.*; import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.service.protocol.*; diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java index 4df88f8cf..4bb670d72 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java @@ -1112,7 +1112,19 @@ public void run() if (currentFilter == null || !currentFilter.equals(filter)) currentFilter = filter; - currentFilter.applyFilter(filterQuery); + // If something goes wrong in our filters, we don't want the + // whole gui to crash. + try + { + currentFilter.applyFilter(filterQuery); + } + catch (Throwable t) + { + if (logger.isInfoEnabled()) + logger.info( + "One of our contact list filters has crashed.", + t); + } } synchronized (this) diff --git a/src/net/java/sip/communicator/service/history/records/HistoryRecord.java b/src/net/java/sip/communicator/service/history/records/HistoryRecord.java index 06488dfcd..c645fcf06 100644 --- a/src/net/java/sip/communicator/service/history/records/HistoryRecord.java +++ b/src/net/java/sip/communicator/service/history/records/HistoryRecord.java @@ -100,4 +100,20 @@ public long getTimeInMillis() { return (timestamp == null) ? 0 : timestamp.getTime(); } + + /** + * Returns the String representation of this HistoryRecord. + * + * @return the String representation of this HistoryRecord + */ + public String toString() + { + String s = "History Record: "; + for (int i = 0; i < propertyNames.length; i++) + { + s += propertyNames[i] + "=" + propertyValues[i] + "\n"; + } + + return s; + } }