More robust parsing in CalendarBuilder

Anonymous
2013-01-01
2013-06-05

  • Anonymous
    2013-01-01

    I struggled for hours to try and get a file to parse that contained a bad date, namely "CREATED:00001231T000000Z" which came from a Google Calendar .ics export.  This causes a  DateParser error - despite the use of CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, true);

    I described the issue in more detail on stack overflow: http://stackoverflow.com/questions/14106844/how-to-make-ical4j-not-fail-on-parsing-errors-like-00001231t000000z/14106976#14106976

    I'd like to suggest that the fix I came up with (adding try/catch around the set method inside propertyValue) is added to the CalendarBuilder class - or at least it is possible to toggle this on/off or easily override to achieve this behaviour. 

    If anyone has a better way to make the parser more robust to bad data, I would love to hear it.  I did not like having to copy the CalendarBuilder class to achieve this.

     

  • Anonymous
    2013-01-01

    To be complete, here is the stack trace: 

    play.exceptions.JavaExecutionException: Error at line 2,945:[CREATED] Unparseable date: "00001231T000000Z"
        at play.mvc.ActionInvoker.invoke(ActionInvoker.java:237)
        at Invocation.HTTP Request(Play!)
    Caused by: net.fortuna.ical4j.data.ParserException: Error at line 2,945:[CREATED] Unparseable date: "00001231T000000Z"
        at net.fortuna.ical4j.data.CalendarParserImpl.parse(CalendarParserImpl.java:148)
        at net.fortuna.ical4j.data.CalendarBuilder.build(CalendarBuilder.java:210)
        at net.fortuna.ical4j.data.CalendarBuilder.build(CalendarBuilder.java:191)
        at net.fortuna.ical4j.data.CalendarBuilder.build(CalendarBuilder.java:179)
        at controllers.Cal.importFile(Cal.java:33)
        at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:557)
        at play.mvc.ActionInvoker.invoke(ActionInvoker.java:508)
        at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:484)
        at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:479)
        at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
        ... 1 more
    Caused by: java.text.ParseException: [CREATED] Unparseable date: "00001231T000000Z"
        at net.fortuna.ical4j.data.CalendarParserImpl$PropertyParser.parse(CalendarParserImpl.java:252)
        at net.fortuna.ical4j.data.CalendarParserImpl$PropertyParser.access$1(CalendarParserImpl.java:200)
        at net.fortuna.ical4j.data.CalendarParserImpl$PropertyListParser.parse(CalendarParserImpl.java:178)
        at net.fortuna.ical4j.data.CalendarParserImpl$ComponentParser.parse(CalendarParserImpl.java:390)
        at net.fortuna.ical4j.data.CalendarParserImpl$ComponentParser.access$1(CalendarParserImpl.java:376)
        at net.fortuna.ical4j.data.CalendarParserImpl$PropertyListParser.parse(CalendarParserImpl.java:175)
        at net.fortuna.ical4j.data.CalendarParserImpl.parse(CalendarParserImpl.java:125)
        ... 10 more
    Caused by: java.text.ParseException: Unparseable date: "00001231T000000Z"
        at java.text.DateFormat.parse(DateFormat.java:337)
        at net.fortuna.ical4j.model.DateTime.setTime(DateTime.java:380)
        at net.fortuna.ical4j.model.DateTime.<init>(DateTime.java:310)
        at net.fortuna.ical4j.model.property.DateProperty.setValue(DateProperty.java:142)
        at net.fortuna.ical4j.data.CalendarBuilder$ContentHandlerImpl.propertyValue(CalendarBuilder.java:318)
        at net.fortuna.ical4j.data.CalendarParserImpl$PropertyParser.parse(CalendarParserImpl.java:249)
        ... 16 more