Fixed
Status Update
Comments
da...@google.com <da...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 3c819141d3be0a6194a6d02e5642942ac15d86af
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Mon Feb 04 10:39:54 2019
Use JetBrains's Kotlin metadata library.
Use kotlinx-metadata-jvm to read Kotlin's Metadata annotation
information. This library has less of an API surface than kotlin-metdata
meaning KotlinClassMetadataUtils only exposes what Room needs. However
it does allows us to fix the JVM descriptors (JvmDescriptorUtils) that
are needed to match annotation processing elements to kotlin metadata
elements.
Bug: 123767877
Test: ./gradlew room:room-compiler:test \
room:integration-tests:room-testapp-kotlin:cC \
room:integration-tests:room-testapp:cC
Change-Id: Iddbe3968865b32168144294e55765a77320a40da
M buildSrc/src/main/kotlin/androidx/build/dependencies/Dependencies.kt
M room/compiler/build.gradle
D room/compiler/src/main/kotlin/androidx/room/ext/KotlinMetadataElement.kt
M room/compiler/src/main/kotlin/androidx/room/ext/element_ext.kt
A room/compiler/src/main/kotlin/androidx/room/kotlin/JvmDescriptorUtils.kt
A room/compiler/src/main/kotlin/androidx/room/kotlin/KotlinClassMetadataUtils.kt
A room/compiler/src/main/kotlin/androidx/room/kotlin/KotlinMetadataElement.kt
M room/compiler/src/main/kotlin/androidx/room/processor/MethodProcessorDelegate.kt
M room/compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/writer/DaoWriter.kt
A room/compiler/src/test/kotlin/androidx/room/kotlin/JvmDescriptorUtilsTest.kt
A room/compiler/src/test/kotlin/androidx/room/kotlin/KotlinMetadataElementTest.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt
A room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/vo/AnswerConverter.kt
https://android-review.googlesource.com/894734
https://goto.google.com/android-sha1/3c819141d3be0a6194a6d02e5642942ac15d86af
Branch: androidx-master-dev
commit 3c819141d3be0a6194a6d02e5642942ac15d86af
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Mon Feb 04 10:39:54 2019
Use JetBrains's Kotlin metadata library.
Use kotlinx-metadata-jvm to read Kotlin's Metadata annotation
information. This library has less of an API surface than kotlin-metdata
meaning KotlinClassMetadataUtils only exposes what Room needs. However
it does allows us to fix the JVM descriptors (JvmDescriptorUtils) that
are needed to match annotation processing elements to kotlin metadata
elements.
Bug: 123767877
Test: ./gradlew room:room-compiler:test \
room:integration-tests:room-testapp-kotlin:cC \
room:integration-tests:room-testapp:cC
Change-Id: Iddbe3968865b32168144294e55765a77320a40da
M buildSrc/src/main/kotlin/androidx/build/dependencies/Dependencies.kt
M room/compiler/build.gradle
D room/compiler/src/main/kotlin/androidx/room/ext/KotlinMetadataElement.kt
M room/compiler/src/main/kotlin/androidx/room/ext/element_ext.kt
A room/compiler/src/main/kotlin/androidx/room/kotlin/JvmDescriptorUtils.kt
A room/compiler/src/main/kotlin/androidx/room/kotlin/KotlinClassMetadataUtils.kt
A room/compiler/src/main/kotlin/androidx/room/kotlin/KotlinMetadataElement.kt
M room/compiler/src/main/kotlin/androidx/room/processor/MethodProcessorDelegate.kt
M room/compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/writer/DaoWriter.kt
A room/compiler/src/test/kotlin/androidx/room/kotlin/JvmDescriptorUtilsTest.kt
A room/compiler/src/test/kotlin/androidx/room/kotlin/KotlinMetadataElementTest.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt
A room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/vo/AnswerConverter.kt
sa...@smartpatient.eu <sa...@smartpatient.eu> #3
This workaround has one big flaw. For not suspended function Room generates __db.assertNotSuspendingTransaction() which will throw IllegalStateException, because of different coroutine dispatcher.
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-master-dev
commit b0d9cda402d404641b5d7c472fdf91dba633eec2
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Fri Jul 19 09:54:42 2019
Extracting suspend fun return type, from 'as member of' executable type.
For base DAOs whose methods will have to be implemented by a derived
class their DAO method signature must be views as member of the
concrete type so that their type arguments are resolved.
Bug: 137878827
Test: ./gradlew kotlin-testapp:cC
Change-Id: I05ac6e02788734dc1eff0d3fbad8bc8b9f745655
M room/compiler/src/main/kotlin/androidx/room/ext/element_ext.kt
M room/compiler/src/main/kotlin/androidx/room/processor/MethodProcessorDelegate.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BaseDao.kt
https://android-review.googlesource.com/1087810
https://goto.google.com/android-sha1/b0d9cda402d404641b5d7c472fdf91dba633eec2
Branch: androidx-master-dev
commit b0d9cda402d404641b5d7c472fdf91dba633eec2
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Fri Jul 19 09:54:42 2019
Extracting suspend fun return type, from 'as member of' executable type.
For base DAOs whose methods will have to be implemented by a derived
class their DAO method signature must be views as member of the
concrete type so that their type arguments are resolved.
Bug: 137878827
Test: ./gradlew kotlin-testapp:cC
Change-Id: I05ac6e02788734dc1eff0d3fbad8bc8b9f745655
M room/compiler/src/main/kotlin/androidx/room/ext/element_ext.kt
M room/compiler/src/main/kotlin/androidx/room/processor/MethodProcessorDelegate.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BaseDao.kt
da...@google.com <da...@google.com> #5
A fix for this will be available in Room 2.2.0-alpha02
Description
Version used: 2.1.0
Devices/Android versions reproduced on: not related
Recently I have updated all Room calls to suspend functions and I discovered that there is an issue with suspend function annotated with @RawQuery which returns generic type.
How to reproduce it?
I'm using base dao for all my entities:
abstract class BaseDao<ENTITY> {
@RawQuery
abstract fun rawQuery(query: SupportSQLiteQuery): List<ENTITY>
}
Example entity:
@Dao
abstract class SampleDao : BaseDao<SampleEntity>()
For this setup Room generates the following implementation:
@Override
public List<SampleEntity> rawQuery(final SupportSQLiteQuery query) {
final SupportSQLiteQuery _internalQuery = query;
__db.assertNotSuspendingTransaction();
final Cursor _cursor = DBUtil.query(__db, _internalQuery, false);
try {
final List<SampleEntity> _result = new ArrayList<SampleEntity>(_cursor.getCount());
while(_cursor.moveToNext()) {
final SampleEntity _item;
_item = __entityCursorConverter_examplePackageSampleEntity(_cursor);
_result.add(_item);
}
return _result;
} finally {
_cursor.close();
}
}
Problems start when I add suspend modifier to rawQuery function:
abstract class BaseDao<ENTITY> {
@RawQuery
abstract suspend fun rawQuery(query: SupportSQLiteQuery): List<ENTITY>
}
Then Room is not able to generate correct implementation and something like that comes out:
@Override
public Object rawQuery(final SupportSQLiteQuery query,
final Continuation<? super List<? extends SampleEntity>> p1) {
final SupportSQLiteQuery _internalQuery = query;
return CoroutinesRoom.execute(__db, false, new Callable<List<? extends ENTITY>>() {
@Override
public List<? extends ENTITY> call() throws Exception {
final Cursor _cursor = DBUtil.query(__db, _internalQuery, false);
try {
return _result;
} finally {
_cursor.close();
}
}
}, p1);
}
I also saw this in 2.2.0-alpha01 and I think issue lies in the code generation.