mangstadt / biweekly

biweekly is an iCalendar library written in Java.
BSD 2-Clause "Simplified" License
323 stars 44 forks source link

NullPointerException when RRule does not contain "FREQ" #84

Closed ashray-aw closed 6 years ago

ashray-aw commented 6 years ago

Hello,

Thank you for this library! We are using the 0.6.1 version of this library and we see a NPE crash when our data does not contain the "FREQ" param in the recurrence rule. I agree it is a required param, but we have servers events with this kind of payload

Full stack trace "biweekly.util.com.google.ical.iter.RecurrenceIteratorFactory.createRecurrenceIterator(RecurrenceIteratorFactory.java:242)" "biweekly.io.ICalTimeZone.createIterator(ICalTimeZone.java:499)" "biweekly.io.ICalTimeZone.getObservanceDateClosestToTheGivenDate(ICalTimeZone.java:385)" "biweekly.io.ICalTimeZone.getObservanceBoundary(ICalTimeZone.java:345)" "biweekly.io.ICalTimeZone.getObservanceBoundary(ICalTimeZone.java:271)" "biweekly.io.ICalTimeZone.getObservance(ICalTimeZone.java:280)" "biweekly.io.ICalTimeZone.calculateRawOffset(ICalTimeZone.java:206)" "biweekly.io.ICalTimeZone.(ICalTimeZone.java:92)" "biweekly.io.StreamReader.handleTimezones(StreamReader.java:175)" "biweekly.io.StreamReader.readNext(StreamReader.java:145)"

Test code

public void testCode() {
        final String calendarBody = "BEGIN:VCALENDAR\n" +
                "VERSION:2.0\n" +
                "PRODID:-//Microsoft Corporation//Outlook for Mac MIMEDIR//EN\n" +
                "METHOD:PUBLISH\n" +
                "BEGIN:VTIMEZONE\n" +
                "TZID:Pacific Time (US & Canada)\n" +
                "X-ENTOURAGE-CFTIMEZONE:US/Pacific\n" +
                "X-ENTOURAGE-TZID:1\n" +
                "BEGIN:STANDARD\n" +
                //RRULE here is missing a required FREQ param
                "RRULE: INTERVAL=1;BYSECOND=0;BYMINUTE=0;BYHOUR=2;BYDAY=1SU;BYMO\n" +
                " NTH=11\n" +
                "TZOFFSETFROM:-0700\n" +
                "TZOFFSETTO:-0800\n" +
                "DTSTART:20071104T020000\n" +
                "END:STANDARD\n" +
                "BEGIN:DAYLIGHT\n" +
                "RRULE:FREQ=YEARLY;INTERVAL=1;BYSECOND=0;BYMINUTE=0;BYHOUR=2;BYDAY=2SU;BYMO\n" +
                " NTH=3\n" +
                "TZOFFSETFROM:-0800\n" +
                "TZOFFSETTO:-0700\n" +
                "DTSTART:20070311T020000\n" +
                "END:DAYLIGHT\n" +
                "END:VTIMEZONE\n" +
                "BEGIN:VEVENT\n" +
                "UID:117937D0-9058-44EB-A92B-D0FE3D1EAF83\n" +
                "X-ENTOURAGE_UUID:87FCA7DD-B623-4BDD-B764-8AF1E32BF9BD\n" +
                "X-MICROSOFT-EXCHANGE-ID:AAMkADhkY2VlNjRhLTMxOTAtNDgxMi05NjlmLWM0ODk5MTA4Yz\n" +
                " dmNwBGAAAAAAA6sLtOP5zCTYONwk1RTaAlBwDtw+J0OEGCRrqz+sTjfceSAAAAAAENAAAs3mz8\n" +
                " 0ouzQ4SZPu6ErZGWAAD+HJpOAAA=\n" +
                "X-MICROSOFT-EXCHANGE-CHANGEKEY:DwAAABYAAAAs3mz80ouzQ4SZPu6ErZGWAAEVuHN7\n" +
                "DTSTAMP:20171018T180557Z\n" +
                "DTSTART;TZID=\"Pacific Time (US & Canada)\":20171016T120000\n" +
                "DTEND;TZID=\"Pacific Time (US & Canada)\":20171016T130000\n" +
                "SUMMARY: Sync Up\n" +
                "DESCRIPTION:\\n\\nRecurring at this time starting mid-October. I’ll find\n" +
                "  some times in the next few weeks for\n" +
                "  us.\\n\\n\\n\\n\\n............................................................\n" +
                " ..........................................................................\n" +
                "LOCATION:Online Meeting\n" +
                "ORGANIZER:MAILTO:someone@somewhare.com\n" +
                "SEQUENCE:1\n" +
                "RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=MO;WKST=SU\n" +
                "ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=FALSE;CN=\"JOhn Doe\n" +
                ";PARTSTAT=ACCEPTED:MAILTO:john@test.com\n" +
                "X-MICROSOFT-CDO-BUSYSTATUS:BUSY\n" +
                "X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\n" +
                "X-MICROSOFT-CDO-ALLDAYEVENT:FALSE\n" +
                "X-MICROSOFT-DISALLOW-COUNTER:FALSE\n" +
                "X-MICROSOFT-CDO-INSTTYPE:1\n" +
                "X-MICROSOFT-CDO-REPLYTIME:20170926T164314Z\n" +
                "BEGIN:VALARM\n" +
                "ACTION:DISPLAY\n" +
                "DESCRIPTION:REMINDER\n" +
                "TRIGGER;RELATED=START:-PT00H15M00S\n" +
                "END:VALARM\n" +
                "END:VEVENT\n";
        InputStream testStream = new ByteArrayInputStream(calendarBody.getBytes());
        ICalReader reader = new ICalReader(testStream);
        try {
            reader.readNext();
            //NPE crash
        } catch (IOException e) {
            //log the exception
        }
    }

Please feel free to let me know if you have any questions

mangstadt commented 6 years ago

Posting code that doesn't compile is very disrespectful. Please take the time to check that your code works before posting it.

Fixed in 11f112ee25c65e34f49bcc5111e205013fe8cd68

ashray-aw commented 6 years ago

Sincere Apologies. I have edited the original post to include code that compiles. And thank you for the fix.