Skip to content
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

Closed
wants to merge 4 commits into from
Closed

Convert ReactPropConstantsTest to Kotlin #39005

wants to merge 4 commits into from

Conversation

thiagobrez
Copy link
Contributor

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:

  1. Run ./gradlew :packages:react-native:ReactAndroid:test.
  2. All tests should pass.

@facebook-github-bot
Copy link
Contributor

Hi @thiagobrez!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

Comment on lines 396 to 399
if(cls == null) {
return new HashMap<>();
};

Copy link
Contributor Author

@thiagobrez thiagobrez Aug 14, 2023

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

Copy link
Contributor

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?

Copy link
Contributor Author

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!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Aug 14, 2023
Copy link
Contributor

@cortinico cortinico left a 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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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<*, *>? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private fun valueAtPath(nestedMap: Map<String, *>?, vararg keyPath: String): Map<*, *>? {
private fun valueAtPath(nestedMap: Map<String, *>, vararg keyPath: String): Map<*, *> {

Comment on lines 396 to 399
if(cls == null) {
return new HashMap<>();
};

Copy link
Contributor

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?

@thiagobrez
Copy link
Contributor Author

@cortinico Of course, I wasn't sure if suppressing was recommended - sending fixes soon!

@thiagobrez
Copy link
Contributor Author

@cortinico Hey, just sent the following fixes:

  • Suppressed the unused variables at the inner class level (ViewManagerUnderTest). Since we're just implementing a dummy class for the test, it seemed like a better idea than suppressing every individual function.

  • Implemented the suggested changes, plus rewrote a few things in valueAtPath to fix the unchecked cast in I had in value?.get(key) as? Map<String, *>. Also, replaced assertThat with require since these were runtime validations. Because of that, I could remove the error() call and get a cleaner return type for the function.

Let me know what you think :)

@thiagobrez thiagobrez requested a review from cortinico August 16, 2023 12:01
@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,947,332 -866
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 9,540,932 -626
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 0ba9808
Branch: main

…react/uimanager/ViewManagersPropertyCache.java
Copy link
Contributor

@cortinico cortinico left a 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

@facebook-github-bot
Copy link
Contributor

@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@cortinico merged this pull request in 4a48fd2.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants