Remove !! from YogaNodeJNIBase (#56841)#56841
Open
cortinico wants to merge 1 commit into
Open
Conversation
|
@cortinico has exported this pull request. If you are a Meta employee, you can view the originating Diff in D105300348. |
!! from YogaNodeJNIBase!! from YogaNodeJNIBase (#56841)
cortinico
added a commit
to cortinico/react-native
that referenced
this pull request
May 15, 2026
Summary: X-link: facebook/yoga#1961 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] - Differential Revision: D105300348
a5ad1d4 to
59b4ed1
Compare
cortinico
added a commit
to cortinico/yoga
that referenced
this pull request
May 15, 2026
Summary: X-link: facebook/react-native#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] - Differential Revision: D105300348
Summary: X-link: facebook/yoga#1961 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] - Differential Revision: D105300348
cortinico
added a commit
to cortinico/yoga
that referenced
this pull request
May 15, 2026
Summary: X-link: facebook/react-native#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] - Differential Revision: D105300348
59b4ed1 to
179a492
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
X-link: facebook/yoga#1961
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 theif (children == null) { children = ArrayList(4) } children!!.add(...)pattern with a singleval list = children ?: ArrayList<YogaNodeJNIBase>(4).also { children = it }so the localvalis statically non-null and lazy-initializes the backing field in one expression.swapChildAt: capturechildreninto a localvalviacheckNotNull(children) { "YogaNode does not have children" }instead ofchildren!!.removeAt(...)/children!!.add(...). Surfaces a clearerIllegalStateExceptioninstead of a bareKotlinNullPointerException.cloneWithChildren: collapseif (clonedYogaNode.children != null) { clonedYogaNode.children = ArrayList(clonedYogaNode.children!!) }intoclonedYogaNode.children?.let { clonedYogaNode.children = ArrayList(it) }.measure: fold the existingif (!isMeasureDefined) throw RuntimeException(...)guard intoval mf = checkNotNull(measureFunction) { "Measure function isn't defined!" }. Same behavior, no double-read of the mutable property.baseline: convert the expression body usingbaselineFunction!!.baseline(...)to a block body that usescheckNotNull(baselineFunction) { "Baseline function isn't defined!" }. Yields a clearer error than a bare NPE ifbaseline()is ever invoked when noYogaBaselineFunctionwas set.Both mirrored copies (
xplat/yoga/...andxplat/js/react-native-github/...) are kept in sync.Changelog:
[Internal] -
Differential Revision: D105300348