GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update JSONParserConfiguration usage in JSONTokener, JSONArray, and JSONObject by michael-ameri · Pull Request #937 · stleary/JSON-java

Conversation

@michael-ameri

@michael-ameri michael-ameri commented Jan 10, 2025

Copy link
Copy Markdown
Contributor
  • fixes Bug: Strict mode is not checked on constructor using JSONTokener and JSONParserConfiguration #935
  • fixes NullPointerExceptions parsing non-strict JSON using JSONTokener from version 20241224 #933
  • resolves JSONTokener reference is retained in JSONObject/JSONArray in 20241224 #927

TODOs, if general approach is accepted, before merging:

  • add missing Javadocs
  • add test cases from other PRs
    -- https://github.com/stleary/JSON-java/pull/934/files#diff-136646e627f31ffe205a70d544d189378bec0a4948fd6b6fd50d541a6dd989a8R494-R527
    -- https://github.com/stleary/JSON-java/pull/936/files#diff-4c5e9ffeff459dde83e61bd6361a19988fc84825ff3b62e40dc775711a5e12e0R328-R343

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Simulant87 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@michael-ameri
remove field references to JSONTokener and JSONParserConfiguration in…
ca1c683
… JSONArray

 and JSONObject
@stleary stleary added the In review label Jan 11, 2025
@stleary

stleary commented Jan 11, 2025

Copy link
Copy Markdown
Owner

@michael-ameri This looks like the right approach, although I am a little surprised it works. Will continue reviewing.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Jan 11, 2025
New unit tests for Strict mode using JSONTokener and JSONParserConfiguration #934
Closed
Bugfix: NullPointerException thrown for invalid input on JSONTokener without strict mode #936
Closed
@Simulant87 Simulant87 mentioned this pull request Jan 11, 2025
Strict mode unit tests #938
Merged
@Simulant87

Simulant87 commented Jan 11, 2025

Copy link
Copy Markdown
Contributor

very good contribution. I added the missing javadoc and adopted my tests in #938 while keeping your commit in the correct git history attribution making it possible to merge #938 instead of this one. If you prefer to have multiple PRs merge, that would also be fine to me, I can also adopt my tests afer this one is merged.

@stleary (Although it would be a backwards compatibility breaking change) I would strongly suggest to remove the getter and setter for JSONParserConfiguration from JSONTokener with the merge of this PR and quickly release a new version to minimise the (faulty) adoption of these methods. Within the library these methods are no longer required. An external caller should not call these methods, as they bring the potential to change the behaviour within a running parsing process, which should use the same configuration end to end.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@michael-ameri

michael-ameri commented Jan 11, 2025

Copy link
Copy Markdown
Contributor Author

@Simulant87

very good contribution. I added the missing javadoc and adopted my tests in #938 while keeping your commit in the correct git history attribution making it possible to merge #938 instead of this one. If you prefer to have multiple PRs merge, that would also be fine to me, I can also adopt my tests afer this one is merged.

thanks for adding the missing parts! I'm totally fine with closing this PR and merging that one.

@stleary (Although it would be a backwards compatibility breaking change) I would strongly suggest to remove the getter and setter for JSONParserConfiguration from JSONTokener

I completely agree with removing the setter (and then making the field final).

Additionally, I think the JSONParserConfiguration shouldn't be passed as an argument in addition to JsonTokener here :

public JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration)

Instead, the JSONParserConfiguration of x should be used. (Same principle for JSONObject constructor)

e.g., what would be the correct behavior, if x.getJsonParserConfiguration().isStrictMode() != jsonParserConfiguration.isStrictMode() ?

Simulant87 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stleary

stleary commented Jan 12, 2025

Copy link
Copy Markdown
Owner

@stleary (Although it would be a backwards compatibility breaking change) I would strongly suggest to remove the getter and setter for JSONParserConfiguration from JSONTokener

I will look into cleaning it up, but since it's already in released code, and not directly causing a problem, removal is probably not on the table.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stleary
stleary marked this pull request as ready for review January 12, 2025 15:39
@stleary

stleary commented Jan 12, 2025

Copy link
Copy Markdown
Owner

What problem does this code solve?

  • Fixes NullPointerException due to uninitialized JSONParserConfiguration
  • Don't store config instance in JSONArray and JSONObject
  • Ensures JSONTokener always has a JSONParserConfiguration instance

Does the code still compile with Java6?
Yes

Risks
Low

Changes to the API?
New API methods have been added

Will this require a new release?
No, but the release cadence will be sped up for this commit.

Should the documentation be updated?
No

Does it break the unit tests?
No. The code was tested manually by defaulting strictmode and then running all unit tests. One test fails (the last case in testValid()), but this will be fixed in a follow up commit. Also manually tested with the unit tests in #934 and #936.

Was any code refactored in this commit?
No

Review status
APPROVED

Starting 3-day comment window

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stleary stleary added Approved - 3-day window and removed In review labels Jan 12, 2025
@stleary

stleary commented Jan 12, 2025

Copy link
Copy Markdown
Owner

Notes:

  • The additional required unit tests in New unit tests for Strict mode using JSONTokener and JSONParserConfiguration #934 and Bugfix: NullPointerException thrown for invalid input on JSONTokener without strict mode #936 will be added in a followup commit.
  • testValid() last test case will be skipped on default strictmode test runs
  • The JSONTokener config setter will be addressed in a followup commit
  • Some aspects of this PR may still be under discussion. Fixes can be done in followup commits after consensus is reached.
nfaupel reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stleary stleary changed the title Remove field references to JSONTokener and JSONParserConfiguration in JSONArray and JSONObject Update JSONParserConfiguration usage in JSONTokener, JSONArray, and JSONObject Jan 12, 2025
@stleary stleary mentioned this pull request Jan 12, 2025
JSONTokener reference is retained in JSONObject/JSONArray in 20241224 #927
Closed
@stleary stleary removed the Approved - 3-day window label Jan 15, 2025
@stleary

stleary commented Jan 15, 2025

Copy link
Copy Markdown
Owner

@michael-ameri Nice work, resolving multiple issues with minimal code changes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

stleary
stleary approved these changes Jan 15, 2025
View reviewed changes
@stleary
stleary merged commit 8c427d9 into stleary:master Jan 15, 2025
@zelite zelite mentioned this pull request May 12, 2025
Release schedule #976
Closed
@DavidJ-Stewart DavidJ-Stewart mentioned this pull request Jan 2, 2026
Consecutive comma handling in JSONArray breaks lenient parsing in 20251224 #1033
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@stleary stleary stleary approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Bug: Strict mode is not checked on constructor using JSONTokener and JSONParserConfiguration NullPointerExceptions parsing non-strict JSON using JSONTokener from version 20241224 JSONTokener reference is retained in JSONObject/JSONArray in 20241224

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@michael-ameri @stleary @Simulant87
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.