Question

I have this code to import calendar from ics file using ical4j:

CalendarBuilder calendarBuilder = new CalendarBuilder();
CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_UNFOLDING, true);
net.fortuna.ical4j.model.Calendar iCalendar;
try {
  iCalendar = calendarBuilder.build(icalInputStream);
} catch (ParserException e) {
  if (logger.isDebugEnabled()) {
    logger.debug("ParserException occurs when building iCalendar object", e);
  }
  throw new ParserException("Cannot parsed the input stream to iCalendar object", e.getLineNo());
}   

The code always throws ParserException. I found that if I remove X-RESPONSE-COMMENT from this line of ics file, the code pass:

ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=TENTATIVE;CN=abc
def;X-NUM-GUESTS=0;X-RESPONSE-COMMENT="JUGSummerCamp.
Si j'arrive à trouver un coin tranquille, je viendrais.":mailto:
abc@gmail.com

So maybe the problem comes from X-RESPONSE-COMMENT. Any one can help? Thanks.

Updated: The exact exception is:

Caused by: java.net.URISyntaxException: Illegal character in path at index 2: Si j'arrive à trouver un coin tranquille, je viendrais.":mailto:slemeur@exoplatform.com
at java.net.URI$Parser.fail(URI.java:2810)
at java.net.URI$Parser.checkChars(URI.java:2983)
at java.net.URI$Parser.parseHierarchical(URI.java:3067)
at java.net.URI$Parser.parse(URI.java:3025)
at java.net.URI.<init>(URI.java:577)
at net.fortuna.ical4j.util.Uris.create(Uris.java:108)
at net.fortuna.ical4j.model.property.Attendee.setValue(Attendee.java:108)
at net.fortuna.ical4j.data.CalendarBuilder.propertyValue(CalendarBuilder.java:294)
at net.fortuna.ical4j.data.CalendarParserImpl.parseProperty(CalendarParserImpl.java:236)
at net.fortuna.ical4j.data.CalendarParserImpl.parsePropertyList(CalendarParserImpl.java:167)
at net.fortuna.ical4j.data.CalendarParserImpl.parseComponent(CalendarParserImpl.java:334)
at net.fortuna.ical4j.data.CalendarParserImpl.parsePropertyList(CalendarParserImpl.java:164)
at net.fortuna.ical4j.data.CalendarParserImpl.parse(CalendarParserImpl.java:107)
... 31 more

The line containing the illegal char is the last line of ATTENDEE property. Thanks.

Was it helpful?

Solution

The X-RESPONSE-COMMENT parameter value has a CRLF (or LF) that is not followed by a whitespace:

JUGSummerCamp.<CRLF>Si j&#39;arrive &agrave; trouver un coin tranquille, je viendrais.

As a consequence, the CRLF is not treated as a line folding sequence but rather as a regular character sequence. But, according to RFC5545, control characters are not allowed in parameter values (see https://www.rfc-editor.org/rfc/rfc5545#section-3.1).

So you can either add a space before the CRLF (making it a line folding one), or remove it altogether (but you may need to fold the line somewhere else - the max line length is 75 characters).

This also means that the intended line break will be lost. There is a relatively recent RFC (RFC6868) which introduce a new encoding that allows formatted text line breaks in parameter values but ical4j does not support it yet as far as I remember. Obviously, the software that originally generated your icalendar stream does not support this RFC either.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top