-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert ReactPropConstantsTest to Kotlin #39005
Convert ReactPropConstantsTest to Kotlin #39005
Conversation
Hi @thiagobrez! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
if(cls == null) { | ||
return new HashMap<>(); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added null-check because cls
was coming null
when calling this function recursively with cls.getSuperClass()
in lines 410-413, causing a NullPointerException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change needed? Was one of your test failing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cortinico Exactly, testNativePropsIncludeCorrectTypes
was failing with a NullPointerException when instantiating the UIManagerModule:
val uiManagerModule = UIManagerModule(reactContext, viewManagers, 0)
I tracked it all the way down to ViewManagersPropertyCache.java, in getNativePropSettersForShadowNodeClass
:
When this function is called recursively (in lines 410-413) with cls.getSuperclass()
, the superclass might be null, causing cls.getInterfaces()
(line 400) to crash.
for (Class iface : cls.getInterfaces()) {
...
}
Let me know if you believe there is a better way to solve this!
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @thiagobrez
Thanks for sending this over!
Can I ask you to fix the warnings that are causing the CI to fail:
> Task :packages:react-native:ReactAndroid:compileDebugUnitTestKotlin FAILED
e: warnings found and -Werror specified
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:50:21 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:50:31 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:54:20 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:54:30 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:58:22 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:58:32 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:62:23 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:62:33 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:66:23 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:66:33 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:70:26 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:70:36 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:74:25 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:74:35 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:78:22 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:78:32 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:82:20 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:82:30 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:86:27 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:86:37 Parameter 'index' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:86:49 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:90:25 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:90:35 Parameter 'index' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:90:47 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:94:30 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:94:40 Parameter 'index' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:94:52 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:98:23 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:98:33 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:105:28 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:105:38 Parameter 'index' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:105:50 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:148:34 Unchecked cast: Any? to Map<String, *>
> Task :packages:react-native:ReactAndroid:compileReleaseUnitTestKotlin FAILED
e: warnings found and -Werror specified
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:50:21 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:50:31 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:54:20 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:54:30 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:58:22 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:58:32 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:62:23 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:62:33 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:66:23 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:66:33 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:70:26 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:70:36 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:74:25 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:74:35 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:78:22 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:78:32 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:82:20 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:82:30 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:86:27 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:86:37 Parameter 'index' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:86:49 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:90:25 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:90:35 Parameter 'index' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:90:47 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:94:30 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:94:40 Parameter 'index' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:94:52 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:98:23 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:98:33 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:105:28 Parameter 'v' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:105:38 Parameter 'index' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:105:50 Parameter 'value' is never used
w: file:///root/react-native/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.kt:148:34 Unchecked cast: Any? to Map<String, *>
as those are tests you'll have to @Suppress
some of the warnings at the class level probably
val viewManagers = listOf<ViewManager<*, *>>(ViewManagerUnderTest()) | ||
val reactContext = ReactApplicationContext(RuntimeEnvironment.getApplication()) | ||
val uiManagerModule = UIManagerModule(reactContext, viewManagers, 0) | ||
val constants: Map<*, *>? = valueAtPath(uiManagerModule.constants, "SomeView", "NativeProps") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val constants: Map<*, *>? = valueAtPath(uiManagerModule.constants, "SomeView", "NativeProps") | |
val constants: Map<*, *> = valueAtPath(uiManagerModule.constants, "SomeView", "NativeProps") |
} | ||
|
||
companion object { | ||
private fun valueAtPath(nestedMap: Map<String, *>?, vararg keyPath: String): Map<*, *>? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private fun valueAtPath(nestedMap: Map<String, *>?, vararg keyPath: String): Map<*, *>? { | |
private fun valueAtPath(nestedMap: Map<String, *>, vararg keyPath: String): Map<*, *> { |
if(cls == null) { | ||
return new HashMap<>(); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change needed? Was one of your test failing?
@cortinico Of course, I wasn't sure if suppressing was recommended - sending fixes soon! |
@cortinico Hey, just sent the following fixes:
Let me know what you think :) |
Base commit: 0ba9808 |
...ative/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java
Outdated
Show resolved
Hide resolved
…react/uimanager/ViewManagersPropertyCache.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know what you think :)
Changes looks great to me 👍 We can import and merge this one now
@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@cortinico merged this pull request in 4a48fd2. |
Summary:
Converts ReactPropConstantsTest to Kotlin, as requested in #38825
Changelog:
[INTERNAL] [CHANGED] - Convert ReactPropConstantsTest to Kotlin
[INTERNAL] [CHANGED] - Add null-check to ViewManagersPropertyCache.java
Test Plan:
./gradlew :packages:react-native:ReactAndroid:test
.