Skip to content

Remove !! from YogaNodeJNIBase (#1961)#1961

Closed
cortinico wants to merge 1 commit into
react:mainfrom
cortinico:export-D105300348
Closed

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

Conversation

@cortinico

@cortinico cortinico commented May 15, 2026

Copy link
Copy Markdown
Contributor

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

@vercel

vercel Bot commented May 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
yoga-website Ready Ready Preview, Comment May 15, 2026 2:20pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed label May 15, 2026
@meta-codesync

meta-codesync Bot commented May 15, 2026

Copy link
Copy Markdown

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

cortinico added a commit to cortinico/react-native that referenced this pull request May 15, 2026
Summary:
X-link: react/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: react/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
@meta-codesync meta-codesync Bot changed the title Remove !! from YogaNodeJNIBase Remove !! from YogaNodeJNIBase (#1961) May 15, 2026
@cortinico cortinico force-pushed the export-D105300348 branch from 249b13f to f4bd0ee Compare May 15, 2026 14:16
Summary:

X-link: react/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 f4bd0ee to 26e69eb Compare May 15, 2026 14:19
cortinico added a commit to cortinico/react-native that referenced this pull request May 15, 2026
Summary:
X-link: react/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-codesync Bot pushed a commit to react/react-native that referenced this pull request May 18, 2026
Summary:
X-link: react/yoga#1961

Pull Request resolved: #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
@meta-codesync meta-codesync Bot closed this in 2c48fef May 18, 2026
@meta-codesync

meta-codesync Bot commented May 18, 2026

Copy link
Copy Markdown

This pull request has been merged in 2c48fef.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant