Status Update
Comments
da...@google.com <da...@google.com> #2
I have a feeling this is related to Duration
being a Kotlin value class and Room trying to use the default the underlying value (a Long
) and failing to realize it can use null
due to converters. Meanwhile Instant
from java.time
is a normal class.
al...@gmail.com <al...@gmail.com> #3
I am using kotlinx.datetime.Instant
.
But anyway, I think you are right, the problem only happens on value classes.
I have another class called Weight
that is also value class, identical to Duration
, and it has the same problem. When I remove the value class
and @JvmInline
the Room code generator correctly assign it null
.
da...@google.com <da...@google.com>
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-main
Author: Daniel Santiago Rivera <
Link:
Add a Room value class test for kotlin.Duration
Expand for full commit details
Add a Room value class test for kotlin.Duration
Bug: 382786786
Test: ValueClassConverterWrapperTest.kt
Change-Id: Ie997f98b54e470c560cbe58537ad0c701e02a199
Files:
- M
room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/vo/DateConverter.kt
- M
room/integration-tests/kotlintestapp/src/androidTestWithKspGenKotlin/java/androidx/room/integration/kotlintestapp/test/ValueClassConverterWrapperTest.kt
Hash: fef109bf650290694ee416c75b40c08c93c76efb
Date: Tue Mar 04 16:04:46 2025
Description
Component used:
Version used:
Devices/Android versions reproduced on:
Description:
In the new multiplatform version, when a field has a custom nullable type (like Duration?), the generated code for the MyDao_Impl in Kotlin has something like this:
Which gives the error "The integer literal does not conform to the expected type Duration?", even though the TypeConverter was correctly set in the abstract implementation of RoomDatabase.
Everything works fine with the previous version that generates the classes in Java.
Oddly, with Instant? it generates correctly:
The converters are almost identical: