Commit 75c00db
feat(java): FR5a — thread source through parser + validation + MetaData.source
Wire the ErrorSource foundation (commit 1) through the canonical JSON
parse pipeline and the per-node validation phase, per ADR-0009.
MetaData base class:
- Adds `private ErrorSource source = CodeSource.DEFAULT` so every node
always has a populated provenance (never null per ADR-0009 §Decision).
- `getSource()` / `setSource(ErrorSource)` API.
- `freezeSource()` / `isSourceFrozen()` freeze guard — once frozen the
setter throws IllegalStateException (mirrors the C# private-set +
Freeze() pattern).
- `setSource(null)` throws NullPointerException with a CodeSource.DEFAULT
hint.
MetaDataException:
- New optional `envelope: ErrorSource` field, exposed via
`getEnvelope(): Optional<ErrorSource>`.
- New convenience constructor `(message, ErrorCode, ErrorSource)` for
loader sites, plus a full 7-arg internal constructor.
- All existing constructors remain back-compat (envelope defaults to
null when not provided).
CanonicalJsonParser:
- Maintains a `JsonPath.Builder` field; pushes/pops keys + indices as
the tree walk descends. The wrapper key, `children`, the array index,
and the fused `<type>.<subType>` key are all pushed in order so the
canonical JSONPath matches the C# / TS oracle byte-identically.
- `tagNodeWithJsonSource(node)` overwrites `CodeSource.DEFAULT` with a
fresh JsonSource on every parser-constructed node (root, structural
children, attr children). Skips if the node already carries a
JsonSource (overlay path) — the merge phase owns transitions to
MergedSource (FR5c slot).
- `currentJsonSource()` builds an envelope at the active JSONPath for
parse-time errors. Wired into the ERR_UNKNOWN_TYPE root check, the
ERR_RESERVED_ATTR @-on-reserved-key throw, and the
ERR_BAD_ATTR_VALUE filter-as-string throw.
ValidationPhase (representative migration; full sweep is incremental):
- field.enum validators now pass `node.getSource()` into the envelope
constructor (ERR_BAD_ATTR_VALUE for malformed @values,
ERR_MISSING_REQUIRED_ATTR when neither own nor inherited @values
present). Pattern for other ValidationPhase sites that have a node
in scope is identical.
Canonical JSON serializer: no changes required. The serializer reads
fields explicitly (name, package, extends, @-attrs, children), so the
new `source` field is naturally omitted from output. Round-trip parity
preserved.
Tests:
- SourceOnNodeTest (9 tests) covers programmatic default
(CodeSource.DEFAULT), setSource() + freeze guard, the JsonSource
length-1 invariant, parser-populated JsonSource at every depth
(root + entity + field), canonical-serializer omission, and
parse-error envelope propagation (ERR_RESERVED_ATTR).
Java metadata suite: 647/647 baseline → 680/680 after FR5a (+33 new
tests across JsonPath/SemanticDiff/SourceOnNode). No regressions.
Refs: ADR-0009, docs/superpowers/specs/2026-05-25-fr5a-json-shape-loader-errors.md
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 80bf081 commit 75c00db
5 files changed
Lines changed: 553 additions & 72 deletions
File tree
- server/java/metadata/src
- main/java/com/metaobjects
- loader
- parser/json
- test/java/com/metaobjects/source
Lines changed: 78 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
278 | 280 | | |
279 | 281 | | |
280 | 282 | | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
281 | 294 | | |
282 | 295 | | |
283 | 296 | | |
| |||
896 | 909 | | |
897 | 910 | | |
898 | 911 | | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
899 | 977 | | |
900 | 978 | | |
901 | 979 | | |
| |||
Lines changed: 60 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
52 | 64 | | |
53 | 65 | | |
54 | 66 | | |
| |||
121 | 133 | | |
122 | 134 | | |
123 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
124 | 157 | | |
125 | 158 | | |
126 | 159 | | |
| 160 | + | |
127 | 161 | | |
128 | 162 | | |
129 | 163 | | |
| |||
139 | 173 | | |
140 | 174 | | |
141 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
142 | 189 | | |
143 | 190 | | |
144 | 191 | | |
| |||
191 | 238 | | |
192 | 239 | | |
193 | 240 | | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
194 | 254 | | |
195 | 255 | | |
196 | 256 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
194 | | - | |
| 195 | + | |
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
| |||
200 | 201 | | |
201 | 202 | | |
202 | 203 | | |
| 204 | + | |
203 | 205 | | |
204 | 206 | | |
205 | 207 | | |
206 | 208 | | |
207 | | - | |
| 209 | + | |
208 | 210 | | |
209 | 211 | | |
210 | 212 | | |
| |||
0 commit comments