← Back to Pull requests

Read an empty array from JSON and property list files #228

Closed
unknown closed this pull request without merging on Oct 02, 2026 14:16 UTC
View on GitHub
unknown unknown commented on Sep 26, 2026 14:42 UTC
Author

Motivation

An empty array in a JSON or property list file reads as no value at all:

// { "tags": [] }

config.stringArray(forKey: "tags")                        // nil
config.stringArray(forKey: "tags", default: ["fallback"]) // ["fallback"]

All four array accessors return nil, and the throwing API reports failed to convert to type stringArray.

Because a key that resolves to no value means "continue to the next provider", an explicitly empty array doesn't shadow a lower-priority source or a default — someone emptying a list to turn something off gets the old value back.

The YAML provider returns [] for the same configuration, so the two file providers disagree with it:

| Provider | ["a"] | [] |
|---|---|---|
| YAML | ["a"] | [] |
| JSON | ["a"] | nil |
| PropertyList | ["a"] | nil |

Modifications

An empty array is parsed into its own emptyArray case, since with no elements there's no element type to infer. That part is right — but none of the array branches in the conversion mention it, so it falls through to throwMismatch().

Handle it in each array branch of both providers:

 case .stringArray:
-    guard case .stringArray(let array) = value else {
+    switch value {
+    case .emptyArray:
+        content = .stringArray([])
+    case .stringArray(let array):
+        content = .stringArray(array)
+    default:
         try throwMismatch()
     }
-    content = .stringArray(array)

Requests for a non-array type still fail, since an array isn't a string. YAML needs no change.

Testing

Added emptyArray to JSONFileProviderTests and PropertyListFileProviderTests, covering all four array accessors, byteChunkArray, a supplied default, and a non-array request. Both fail on main and pass with this change.

No existing test constructs an empty array in any format.

Full suite with --traits JSON,YAML,PropertyList: 118 tests, 0 failures. Default traits: 110, 0 failures. swift format lint --strict clean.

Related

This is the second place where an explicitly empty value is treated as absent — #227 covers KEY= in environment files. Different code, same consequence. Might be worth a look at the other providers.

Diff: 278 lines (+208 / -70) across 3 files Reviewer: czechboy0 Review duration: 8614m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 278 lines diff across 3 files
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.337
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #228"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 39.6% (MEDIUM) · Higher = larger blast radius
39.6%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 15.7% · Safe to merge
15.7%