CompletedBuilder: Fix LocalDateTime cannot be cast to Instant#424
Open
sunkup wants to merge 4 commits into
Open
CompletedBuilder: Fix LocalDateTime cannot be cast to Instant#424sunkup wants to merge 4 commits into
LocalDateTime cannot be cast to Instant#424sunkup wants to merge 4 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a runtime ClassCastException in the DMFS task mapping when building the COMPLETED field from iCalendar data by normalizing temporals before converting them to provider timestamps.
Changes:
- Update
CompletedBuilderto convertcompletedAtvianormalizedDate()+toTimestamp()(instead of assumingInstant). - Add a regression test covering floating
COMPLETED(timezone-less) date-times to ensure the builder does not crash and produces the expected timestamp.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/src/main/kotlin/at/bitfire/synctools/mapping/tasks/builder/CompletedBuilder.kt | Fixes COMPLETED timestamp generation by normalizing temporals and using the shared timestamp conversion helper. |
| lib/src/test/kotlin/at/bitfire/synctools/mapping/tasks/builder/CompletedBuilderTest.kt | Adds a regression test for floating COMPLETED values to prevent reintroducing the crash. |
LocalDateTime cannot be cast to Instant
0525080 to
0111b70
Compare
0111b70 to
a9ecfe7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
ClassCastExceptioninCompletedBuilder : DmfsTaskFieldBuilderwhenDmfsTaskBuilder.buildTaskruns.The exception users get is
ClassCastException: LocalDateTime cannot be cast to Instantso must occur where code assumesInstantat runtime but getsLocalDateTime.DmfsTaskBuilder.buildTaskloops over all fieldBuilders calling .build()` so the crash must be inside one of them.StartTimeBuilderandDueBuilderusenormalizedDate()?.toTimestamp(), butCompletedBuilderdoes not. It uses.date?.toEpochMilli()which works only onInstant(!), so any non-Instant temporal here causes exactly this exception.Relevant changes made:
completedAt?.normalizedDate()?.toTimestamp()in COMPLETED builder instead ofcompletedAt?.date?.toEpochMilli().Also:
toTimestampwhich was loosing milliseconds. ChangedtoInstant().epochSecond * 1000totoInstant().toEpochMilli().