[java] Enforce commas between JSON elements; accept trailing commas#17738
[java] Enforce commas between JSON elements; accept trailing commas#17738shs96c wants to merge 4 commits into
Conversation
283346f to
82c7465
Compare
PR Summary by QodoJsonInput: require commas between elements and allow trailing commas
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
Context used✅ Compliance rules (platform):
18 rules 1.
|
42e746e to
1f44b29
Compare
|
Code review by qodo was updated up to the latest commit 1f44b29 |
|
Code review by qodo was updated up to the latest commit 6cb2aa0 |
hasNext() previously consumed a leading comma if present, but never required one. That accepted spec-invalid inputs like '[1 2 3]' (missing separator) and '[,1]' (leading comma). It also rejected trailing commas like '[1,2,3,]' because it consumed the comma and then tried to read another element. Track whether the current container has seen an element (parallel deque kept in sync with the container stack, marked in expect()) and use it in hasNext() to require a comma between elements while allowing a single trailing comma before the container's closer.
hasNext() consumed the comma between elements but did not clear the 'container has element' flag, so a second hasNext() before reading the next value threw as if the comma were missing. Iterator-style callers that probe multiple times per element saw spurious failures on valid input like [1,2].
6cb2aa0 to
73987ab
Compare
|
Code review by qodo was updated up to the latest commit 73987ab |
endArray()/endObject() popped the container stacks before checking the container type, so a mismatched close corrupted parser state on top of throwing. Check first, pop after. Also cover object-side comma enforcement with tests to match the existing array cases.
|
Code review by qodo was updated up to the latest commit b91099f |
JsonInput.hasNext()had two spec-compliance gaps and one usability gap:[1 2 3]and{\"a\":1 \"b\":2}both parsed successfully.[,1]parsed as[1].[1,2,3,]even though we want to be lenient about that.Handle these by:
containerHasElementdeque kept in sync with the container stack.expect()when reading a value (or completing a name/value pair).hasNext()to require a separator between elements while allowing a single trailing comma before]/}, and to reject a leading comma.