From 533b627b2bfa340a7c767f6af8a5cf1378936ef1 Mon Sep 17 00:00:00 2001 From: mguessan Date: Tue, 5 Oct 2010 22:23:35 +0000 Subject: [PATCH] Caldav: fix nullpointer in VCalendar on missing DTEND git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1494 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/exchange/VCalendar.java | 40 ++++++++++--------- .../exchange/TestExchangeSessionEvent.java | 19 +++++---- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/java/davmail/exchange/VCalendar.java b/src/java/davmail/exchange/VCalendar.java index 56471c7c..7da998e7 100644 --- a/src/java/davmail/exchange/VCalendar.java +++ b/src/java/davmail/exchange/VCalendar.java @@ -259,27 +259,29 @@ public class VCalendar extends VObject { } protected void setClientAllday(VProperty property) { - // set VALUE=DATE param - if (!property.hasParam("VALUE")) { - property.addParam("VALUE", "DATE"); - } - // remove TZID - property.removeParam("TZID"); - String value = property.getValue(); - if (value.length() != 8) { - // try to convert datetime value to date value - try { - Calendar calendar = Calendar.getInstance(); - SimpleDateFormat dateParser = new SimpleDateFormat("yyyyMMdd'T'HHmmss"); - calendar.setTime(dateParser.parse(value)); - calendar.add(Calendar.HOUR_OF_DAY, 12); - SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd"); - value = dateFormatter.format(calendar.getTime()); - } catch (ParseException e) { - LOGGER.warn("Invalid date value in allday event: " + value); + if (property != null) { + // set VALUE=DATE param + if (!property.hasParam("VALUE")) { + property.addParam("VALUE", "DATE"); } + // remove TZID + property.removeParam("TZID"); + String value = property.getValue(); + if (value.length() != 8) { + // try to convert datetime value to date value + try { + Calendar calendar = Calendar.getInstance(); + SimpleDateFormat dateParser = new SimpleDateFormat("yyyyMMdd'T'HHmmss"); + calendar.setTime(dateParser.parse(value)); + calendar.add(Calendar.HOUR_OF_DAY, 12); + SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd"); + value = dateFormatter.format(calendar.getTime()); + } catch (ParseException e) { + LOGGER.warn("Invalid date value in allday event: " + value); + } + } + property.setValue(value); } - property.setValue(value); } protected void fixAlarm(VObject vObject, boolean fromServer) { diff --git a/src/test/davmail/exchange/TestExchangeSessionEvent.java b/src/test/davmail/exchange/TestExchangeSessionEvent.java index 617c56c9..fd9eb2de 100644 --- a/src/test/davmail/exchange/TestExchangeSessionEvent.java +++ b/src/test/davmail/exchange/TestExchangeSessionEvent.java @@ -294,14 +294,17 @@ public class TestExchangeSessionEvent extends TestCase { "PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN\n" + "VERSION:2.0\n" + "BEGIN:VEVENT\n" + - "CREATED:20100916T115132Z\n" + - "LAST-MODIFIED:20100916T115138Z\n" + - "DTSTAMP:20100916T115138Z\n" + - "UID:d72ff8cc-f3ee-4fbc-b44d-1aaf78d92847\n" + - "SUMMARY:New Event\n" + - "DTSTART;VALUE=DATE:20100929\n" + - "DTEND;VALUE=DATE:20100930\n" + - "TRANSP:TRANSPARENT\n" + + "CREATED:20090906T141628Z\n" + + "LAST-MODIFIED:20090906T141630Z\n" + + "DTSTAMP:20090820T162854Z\n" + + "UID:20090820T182854CEST-774934hSZ6@education.gouv.fr\n" + + "SUMMARY:Rentrée scolaire des enseignants - Zone C\n" + + "DTSTART;TZID=\"null\":20080901T000000\n" + + "DESCRIPTION:Rentrée scolaire des enseignants\n" + + "LOCATION:France\n" + + "X-MICROSOFT-CDO-BUSYSTATUS:BUSY\n" + + "X-MICROSOFT-CDO-ALLDAYEVENT:TRUE\n" + + "ORGANIZER:MAILTO:laurent.bazin@chu-bordeaux.fr\n" + "END:VEVENT\n" + "END:VCALENDAR"; String toServer = fixICS(itemBody, true);