A framework for building native applications using React
Remove `!!` from `YogaNodeJNIBase` (#56841)
Summary:
X-link: https://github.com/facebook/yoga/pull/1961
Pull Request resolved: https://github.com/facebook/react-native/pull/56841
Follow-up to D104666335 (Yoga Java→Kotlin migration of `YogaNodeJNIBase`). The original migration kept several `!!` (not-null assertion) operators. Per reviewer feedback, replace them with safer Kotlin idioms:
- `addChildAt`: replace the `if (children == null) { children = ArrayList(4) } children!!.add(...)` pattern with a single `val list = children ?: ArrayList<YogaNodeJNIBase>(4).also { children = it }` so the local `val` is statically non-null and lazy-initializes the backing field in one expression.
- `swapChildAt`: capture `children` into a local `val` via `checkNotNull(children) { "YogaNode does not have children" }` instead of `children!!.removeAt(...)` / `children!!.add(...)`. Surfaces a clearer `IllegalStateException` instead of a bare `KotlinNullPointerException`.
- `cloneWithChildren`: collapse `if (clonedYogaNode.children != null) { clonedYogaNode.children = ArrayList(clonedYogaNode.children!!) }` into `clonedYogaNode.children?.let { clonedYogaNode.children = ArrayList(it) }`.
- `measure`: fold the existing `if (!isMeasureDefined) throw RuntimeException(...)` guard into `val mf = checkNotNull(measureFunction) { "Measure function isn't defined!" }`. Same behavior, no double-read of the mutable property.
- `baseline`: convert the expression body using `baselineFunction!!.baseline(...)` to a block body that uses `checkNotNull(baselineFunction) { "Baseline function isn't defined!" }`. Yields a clearer error than a bare NPE if `baseline()` is ever invoked when no `YogaBaselineFunction` was set.
Both mirrored copies (`xplat/yoga/...` and `xplat/js/react-native-github/...`) are kept in sync.
Changelog:
[Internal] -
Reviewed By: cipolleschi
Differential Revision: D105300348
fbshipit-source-id: 61a5efd32bc43dbc499ea474e7ebbd2cbc6c2219 N
Nicola Corti committed
35771c64e9aa6ce73efa79314d8af00ff8ec6371
Parent: aee2bd7
Committed by meta-codesync[bot] <215208954+meta-codesync[bot]@users.noreply.github.com>
on 5/18/2026, 2:11:31 PM