Skip to content

Fix mishandling of exceptions in UTC#2268

Closed
ArnyminerZ wants to merge 2 commits into
mainfrom
fix-davx5-898
Closed

Fix mishandling of exceptions in UTC#2268
ArnyminerZ wants to merge 2 commits into
mainfrom
fix-davx5-898

Conversation

@ArnyminerZ

Copy link
Copy Markdown
Member

Purpose

Closes https://github.com/bitfireAT/davx5/issues/898

The TemporalAdapter.isBefore call in ICalendarGenerator.write crashed when comparing a UTC Instant (for example 2025-08-22T03:30:00Z from an exception's DTSTART) against a ZonedDateTime (from the main event's DTSTART), because ical4j internally tries ZonedDateTime.from(Instant) which always throws DateTimeException.

Short description

Added a failing test that showcases the issue, and a fix for it.

Copy of bitfireAT/synctools#442

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

Signed-off-by: Arnau Mora Gras <arnyminerz@proton.me>
@ArnyminerZ ArnyminerZ self-assigned this May 26, 2026
@ArnyminerZ ArnyminerZ added the refactoring Internal improvement of existing functions label May 26, 2026
@ArnyminerZ ArnyminerZ requested a review from Copilot May 26, 2026 15:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an iCal generation crash when recurrence exceptions use a UTC Instant for DTSTART and the main event uses a ZonedDateTime, by avoiding ical4j’s problematic cross-type comparison and adding a regression test.

Changes:

  • Add a regression test that writes an event with a UTC Instant exception DTSTART and verifies generation succeeds.
  • Update ICalendarGenerator.write to compare exception start times by converting Temporal values to Instant before ordering.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
synctools/src/main/kotlin/at/bitfire/synctools/icalendar/ICalendarGenerator.kt Prevents the crash by comparing exception/main start times via Instant conversion instead of TemporalAdapter.isBefore.
synctools/src/test/kotlin/at/bitfire/synctools/icalendar/ICalendarGeneratorTest.kt Adds coverage for the UTC-Instant exception DTSTART scenario to prevent regressions.

@ArnyminerZ ArnyminerZ marked this pull request as ready for review May 26, 2026 16:05
@ArnyminerZ ArnyminerZ requested a review from rfc2822 May 26, 2026 16:05
@rfc2822 rfc2822 requested review from sunkup and removed request for rfc2822 May 26, 2026 16:32
Comment on lines +69 to +72
// Convert both Temporals to Instants for comparison, because they may be in different time zones. If conversion fails, ignore the start date of this exception.
val startInstant = runCatching { start.toInstant() }.getOrNull() ?: return@let
val earliestInstant = earliestStart?.let { runCatching { it.toInstant() }.getOrNull() }
if (earliestInstant == null || startInstant < earliestInstant)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: Maybe explicitly check for the expected types, handle them and throw a specific Exception if it's not one of the supported types? I'd find it easier to understand if it would be clear when toInstant is expected to work and when not, instead of using a somehow intransparent runCatching.

But didn't look in depth, just an idea.

Also have unassigned myself (not available tomorrow)

@rfc2822 rfc2822 added pr-bugfix Fixes something that isn't working (only used for PRs) events Regarding events / everything that's stored in Android Calendar Provider and removed refactoring Internal improvement of existing functions labels May 27, 2026

@sunkup sunkup left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well, but I second what Ricki says.

@devvv4ever

This comment was marked as duplicate.

Signed-off-by: Arnau Mora Gras <arnyminerz@proton.me>
@rfc2822

rfc2822 commented May 28, 2026

Copy link
Copy Markdown
Member

Superseded by #2280

@rfc2822 rfc2822 closed this May 28, 2026
@rfc2822 rfc2822 deleted the fix-davx5-898 branch June 5, 2026 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

events Regarding events / everything that's stored in Android Calendar Provider pr-bugfix Fixes something that isn't working (only used for PRs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants