Skip to content

Remove !! from YogaNodeJNIBase (#56841)#56841

Open
cortinico wants to merge 1 commit into
facebook:mainfrom
cortinico:export-D105300348
Open

Remove !! from YogaNodeJNIBase (#56841)#56841
cortinico wants to merge 1 commit into
facebook:mainfrom
cortinico:export-D105300348

Conversation

@cortinico
Copy link
Copy Markdown
Contributor

@cortinico cortinico commented 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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 15, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented May 15, 2026

@cortinico has exported this pull request. If you are a Meta employee, you can view the originating Diff in D105300348.

@meta-codesync meta-codesync Bot changed the title Remove !! from YogaNodeJNIBase Remove !! from YogaNodeJNIBase (#56841) May 15, 2026
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
@cortinico cortinico force-pushed the export-D105300348 branch from a5ad1d4 to 59b4ed1 Compare May 15, 2026 14:16
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
@cortinico cortinico force-pushed the export-D105300348 branch from 59b4ed1 to 179a492 Compare May 15, 2026 14:19
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. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant