Skip to content

Fix JsonScanner number parsing for bare exponents and -Infinity - #16284

Merged
borinquenkid merged 1 commit into
7.0.xfrom
fix/json-scanner-number-parsing
Sep 2, 2026
Merged

borinquenkid merged 1 commit into
7.0.xfrom
fix/json-scanner-number-parsing

Conversation

@borinquenkid

Copy link
Copy Markdown
Member

Summary

  • SAW_EXPONENT_DIGITS was the only numeric scanner state whose terminator switch omitted an explicit end-of-input case, so a bare exponent-notation number with nothing following it (e.g. a top-level 1e2) threw JsonParseException instead of parsing.
  • SAW_MINUS_I appended the character it read on every iteration of its -Infinity match loop, including the terminator character read immediately after matching the literal's final y - so the buffer handed to Double.parseDouble always carried one extra trailing character, and -Infinity failed to parse in every context (end-of-input, before a comma, before a closing bracket).
  • Found while adding broader JsonReader/JsonWriter test coverage on 8.1.x; JsonScanner is unchanged since 7.0.x, so the fix applies cleanly here. This branch had no prior JsonReader test coverage, so a minimal JsonReaderSpec is added with just the two regression tests.

Test plan

  • ./gradlew :grails-data-mongodb-bson:test - full module suite green, including the two new regression tests
  • ./gradlew :grails-data-mongodb-bson:codeStyle - clean

🤖 Generated with Claude Code

https://claude.ai/code/session_01QAjfckcY4EJsxranv1RyGV

Two bugs found while adding test coverage for JsonReader/JsonWriter on
8.1.x, cherry-picked here since JsonScanner is unchanged since 7.0.x:

- SAW_EXPONENT_DIGITS was the only numeric scanner state whose
  terminator switch omitted an explicit end-of-input case (every
  sibling state treats EOF the same as a closing delimiter), so a
  bare exponent-notation number with nothing following it (e.g. a
  top-level "1e2") threw JsonParseException instead of parsing.

- SAW_MINUS_I appended the character it read on every iteration of
  its "-Infinity" match loop, including the terminator character read
  immediately after matching the literal's final 'y' - so the buffer
  handed to Double.parseDouble always carried one extra trailing
  character, and "-Infinity" failed to parse in every context
  (end-of-input, before a comma, before a closing bracket).

This branch has no prior JsonReader test coverage, so a minimal
JsonReaderSpec is added here with just the two regression tests -
broader JsonReader/JsonWriter coverage exists only on 8.1.x.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QAjfckcY4EJsxranv1RyGV

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes two edge-case bugs in the BSON JSON parsing implementation (JsonScanner) and adds targeted regression coverage to prevent reintroduction. It improves correctness for numeric tokenization at end-of-input and for the -Infinity literal, which are both important for robust JSON/BSON interoperability in the grails-data-mongodb module.

Changes:

  • Fix SAW_EXPONENT_DIGITS to correctly terminate on end-of-input (-1) so top-level exponent numbers like 1e2 parse successfully.
  • Fix -Infinity scanning to avoid appending the post-literal terminator character into the numeric buffer (preventing Double.parseDouble failures).
  • Add a minimal JsonReaderSpec with two regression tests covering these scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
grails-data-mongodb/bson/src/main/groovy/org/grails/datastore/bson/json/JsonScanner.java Correct EOF handling for exponent parsing and fix -Infinity buffer construction so numeric parsing succeeds across delimiters/EOF.
grails-data-mongodb/bson/src/test/groovy/org/grails/datastore/bson/json/JsonReaderSpec.groovy Add regression tests validating bare exponent parsing and -Infinity parsing at EOF and inside an array.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@testlens-app

testlens-app Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

🚨 TestLens detected 1 failed test 🚨

Here is what you can do:

  1. Inspect the test failures carefully.
  2. If you are convinced that some of the tests are flaky, you can mute them below.
  3. Finally, trigger a rerun by checking the rerun checkbox.

Test Summary

Groovy Snapshot Canary Build / Build Grails (shard 2) > :grails-test-examples-scaffolding:integrationTest

Test Runs Flakiness
UserControllerSpec > User list ❌ 3% 🟡

🏷️ Commit: 070707e
▶️ Tests: 119754 executed
⚪️ Checks: 138/138 completed

Test Failures

UserControllerSpec > User list (:grails-test-examples-scaffolding:integrationTest in Groovy Snapshot Canary Build / Build Grails (shard 2))
geb.waiting.WaitTimeoutException: condition did not pass in 30 seconds (failed with exception)
	at geb.waiting.Wait.waitFor(Wait.groovy:128)
	at geb.waiting.DefaultWaitingSupport.doWaitFor(DefaultWaitingSupport.groovy:55)
	at geb.waiting.DefaultWaitingSupport.waitFor(DefaultWaitingSupport.groovy:41)
	at geb.Page.waitFor(Page.groovy:120)
	at com.example.pages.LoginPage.login(LoginPage.groovy:39)
	at com.example.UserControllerSpec.User list(UserControllerSpec.groovy:48)
Caused by: Assertion failed: 

title != pageTitle && $('input', name: 'username').empty
|     |  |         |
|     |  |         false
|     |  'Please sign in'
|     false
'Please sign in'

	at com.example.pages.LoginPage.login_closure1(LoginPage.groovy:39)
	at com.example.pages.LoginPage.login_closure1(LoginPage.groovy)
	at geb.waiting.Wait.waitFor(Wait.groovy:117)
	... 5 more

Rerun Controls

Select tests to mute in this pull request:

  • UserControllerSpec > User list

Reuse successful test results:

  • ♻️ Only rerun the tests that failed or were muted before

Click the checkbox to trigger a rerun:

  • Rerun jobs

Learn more about TestLens at testlens.app/docs.

@borinquenkid
borinquenkid merged commit 2f7a097 into 7.0.x Sep 2, 2026
140 of 141 checks passed
@borinquenkid
borinquenkid deleted the fix/json-scanner-number-parsing branch September 2, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants