Skip to content

Commit 954589d

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Fix KotlinGenericsCast lint warning in getNativeModule
Summary: **Lint Issue:** ANDROIDLINT KotlinGenericsCast warning on line 361. The `getNativeModule` function casts `turboModuleManager.getModule(nativeModuleName)` to generic type `T?`. The lint warns that casts to erased Kotlin generic type references are only checked at compile time, and at runtime, casts to type arguments of a generic function are unchecked due to type erasure. **Fix:** Added `SuppressLint("KotlinGenericsCast")` annotation to the function. The existing `Suppress("UNCHECKED_CAST")` only suppresses the Kotlin compiler warning, not the AndroidLint warning. This cast is intentional and unavoidable given the API design where callers specify the expected return type. changelog: [internal] internal Reviewed By: alanleedev Differential Revision: D91709481
1 parent ab7a5e3 commit 954589d

File tree

1 file changed

+2
-0
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime

1 file changed

+2
-0
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package com.facebook.react.runtime
99

10+
import android.annotation.SuppressLint
1011
import android.content.res.AssetManager
1112
import android.view.View
1213
import com.facebook.common.logging.FLog
@@ -359,6 +360,7 @@ internal class ReactInstance(
359360
return null
360361
}
361362

363+
@SuppressLint("KotlinGenericsCast")
362364
fun <T : NativeModule> getNativeModule(nativeModuleName: String): T? {
363365
synchronized(turboModuleManager) {
364366
@Suppress("UNCHECKED_CAST")

0 commit comments

Comments
 (0)