[GH] Fix issue caused by custom classloader.
## Proposed Changes
- Passing the specified class loader to fix ClassNotFoundException when app contains multiple class loaders.
## Testing
Test: ./gradlew test connectedCheck -x :room:room-benchmark:cC -x :room:integration-tests:room-incremental-annotation-processing:test;./gradlew updateApi
## Issues Fixed
Fixes: The bug on [170141113](https://issuetracker.google.com/issues/170141113) being fixed
This is an imported pull request from https://github.com/androidx/androidx/pull/86.
Resolves #86
Github-Pr-Head-Sha: 4a3cb6dec47579d9229bb0252f9943033ee2f8ea
GitOrigin-RevId: 9fd32b1595849c6f5c1fbd154c548157408a12e0
Change-Id: I99d47d48ab9415d4f66d681285d62c0439717876
diff --git a/room/runtime/src/main/java/androidx/room/Room.java b/room/runtime/src/main/java/androidx/room/Room.java
index cadf56c..6a570c4 100644
--- a/room/runtime/src/main/java/androidx/room/Room.java
+++ b/room/runtime/src/main/java/androidx/room/Room.java
@@ -85,9 +85,12 @@
//noinspection TryWithIdenticalCatches
try {
+ final String fullClassName = fullPackage.isEmpty()
+ ? implName
+ : fullPackage + "." + implName;
@SuppressWarnings("unchecked")
final Class<T> aClass = (Class<T>) Class.forName(
- fullPackage.isEmpty() ? implName : fullPackage + "." + implName);
+ fullClassName, true, klass.getClassLoader());
return aClass.newInstance();
} catch (ClassNotFoundException e) {
throw new RuntimeException("cannot find implementation for "