Commit 249b13f
Remove
Summary:
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!! from YogaNodeJNIBase
1 parent 35e842f commit 249b13f
1 file changed
Lines changed: 12 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 73 | + | |
| 74 | + | |
77 | 75 | | |
78 | 76 | | |
79 | 77 | | |
| |||
89 | 87 | | |
90 | 88 | | |
91 | 89 | | |
92 | | - | |
93 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
94 | 93 | | |
95 | 94 | | |
96 | 95 | | |
97 | 96 | | |
98 | 97 | | |
99 | 98 | | |
100 | 99 | | |
101 | | - | |
102 | | - | |
103 | | - | |
| 100 | + | |
104 | 101 | | |
105 | 102 | | |
106 | 103 | | |
| |||
540 | 537 | | |
541 | 538 | | |
542 | 539 | | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
| 540 | + | |
| 541 | + | |
548 | 542 | | |
549 | 543 | | |
550 | 544 | | |
| |||
560 | 554 | | |
561 | 555 | | |
562 | 556 | | |
563 | | - | |
564 | | - | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
565 | 561 | | |
566 | 562 | | |
567 | 563 | | |
| |||
0 commit comments