From 0c16e200f71dfbc68eb091c662704ca7551183cb Mon Sep 17 00:00:00 2001 From: Nazzareno Sileno Date: Wed, 16 Dec 2015 18:29:43 +0100 Subject: [PATCH] FIX Null Pointer Exception When you try to use the method getCalendarEventId(...) and the parent class returns null for getDesktop() the NPE is thrown. I added a simple check to avoid to throw NPE and few loc to generate a random UUID in case of lack of Desktop Object. --- calendar/src/org/zkoss/calendar/Calendars.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/calendar/src/org/zkoss/calendar/Calendars.java b/calendar/src/org/zkoss/calendar/Calendars.java index 035dea4..d3fec65 100644 --- a/calendar/src/org/zkoss/calendar/Calendars.java +++ b/calendar/src/org/zkoss/calendar/Calendars.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.TimeZone; +import java.util.UUID; import org.zkoss.calendar.api.CalendarEvent; import org.zkoss.calendar.api.CalendarModel; @@ -453,11 +454,13 @@ public Map getTimeZones() { public String getCalendarEventId(CalendarEvent ce) { Object o = _ids.get(ce); - if (o == null) { + if (o == null && super.getDesktop() != null) { o = ((DesktopCtrl)getDesktop()).getNextUuid(this); _ids.put(o, ce); _ids.put(ce, o); - } + } else if (o == null) { + o = UUID.randomUUID().toString(); + } return (String) o; }