Problem with ExDate - is it a bug?

Help
2013-03-27
2013-06-05
  • I am having problems with the ExDate property, when using date-only values (no time).
    I try to add an EXDATE for a specific date. When I write the calendar to a file, a time value (of 00:00:00) is added. This results in an unparseable date (because it is not just a date anymore):

    net.fortuna.ical4j.data.ParserException: Error at line 9:[EXDATE] Unparseable date: "20130311T000000Z"
        at net.fortuna.ical4j.data.CalendarParserImpl.parse(CalendarParserImpl.java:148)
    

    I have written a JUnit test to demonstrate the problem. Please let me know if I am doing something wrong, or if this is a bug in iCal4j.

    See my unit test here:
    https://gist.github.com/popstr/5254001

    The test fails with this message:

    net.fortuna.ical4j.data.ParserException: Error at line 9:[EXDATE] Unparseable date: "20130311T000000Z"
        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 RecurringTest.test(RecurringTest.java:90)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
        at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
        at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
    Caused by: java.text.ParseException: [EXDATE] Unparseable date: "20130311T000000Z"
        at net.fortuna.ical4j.data.CalendarParserImpl$PropertyParser.parse(CalendarParserImpl.java:258)
        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:396)
        at net.fortuna.ical4j.data.CalendarParserImpl$ComponentParser.access$1(CalendarParserImpl.java:382)
        at net.fortuna.ical4j.data.CalendarParserImpl$PropertyListParser.parse(CalendarParserImpl.java:175)
        at net.fortuna.ical4j.data.CalendarParserImpl.parse(CalendarParserImpl.java:125)
        ... 30 more
    Caused by: java.text.ParseException: Unparseable date: "20130311T000000Z"
        at java.text.DateFormat.parse(DateFormat.java:357)
        at net.fortuna.ical4j.model.Date.<init>(Date.java:146)
        at net.fortuna.ical4j.model.DateList.<init>(DateList.java:138)
        at net.fortuna.ical4j.model.property.DateListProperty.setValue(DateListProperty.java:116)
        at net.fortuna.ical4j.data.CalendarBuilder$ContentHandlerImpl.propertyValue(CalendarBuilder.java:318)
        at net.fortuna.ical4j.data.CalendarParserImpl$PropertyParser.parse(CalendarParserImpl.java:255)
        ... 36 more
    
     
  • So I managed to find a workaround. Replacing lines 55-60 with this solves the problem:

    // Except for 11 March 2013
    DateList dateList = new DateList(Value.DATE);
    dateList.add(new Date("20130311", "yyyyMMdd"));
    ExDate exDate = new ExDate(dateList);
    event.getProperties().add(exDate);
    

    I still think it would be better if you could set the type of the DateList through the ExDate object.

    But take a look at line 200 in net.fortuna.ical4j.model.DateList (version 1.0.4, the latest one right now). Why is it checking the type field, instad of checking if the date parameter is instance of Date like for DateTime?

    Anyway, great job with this library!