Skip to content

Fix: type safety in Android build configuration for React Native directory resolution#9652

Open
benjaminpeters wants to merge 1 commit into
software-mansion:mainfrom
benjaminpeters:fix/REACT_NATIVE_NODE_MODULES_DIR-casting
Open

Fix: type safety in Android build configuration for React Native directory resolution#9652
benjaminpeters wants to merge 1 commit into
software-mansion:mainfrom
benjaminpeters:fix/REACT_NATIVE_NODE_MODULES_DIR-casting

Conversation

@benjaminpeters

Copy link
Copy Markdown

Summary

Setting REACT_NATIVE_NODE_MODULES_DIR = file("$rootDir/$NODE_MODULES_DIR/react-native") will throw class java.io.File cannot be cast to class java.lang.String (java.io.File and java.lang.String are in module java.base of loader 'bootstrap')

Changes

  • Updated resolveReactNativeDirectory() function in both react-native-reanimated and
    react-native-worklets Android build files
  • Replaced unsafe string casting with proper type checking using Kotlin's when expression
  • Now handles multiple possible types for REACT_NATIVE_NODE_MODULES_DIR:
    • File objects (returned as-is)
    • String values (converted to File)
    • Other types (converted to string then File)

Why

The previous code assumed REACT_NATIVE_NODE_MODULES_DIR would always be a String and used an unsafe cast (as String?). This could cause ClassCastException at runtime if the property was set to a different type (like a File object).

Test plan

  • Verify Android builds complete successfully
  • Test with different monorepo configurations
  • Confirm no regressions in React Native directory resolution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant