Skip to content

fix: stop mutating JsonPath JVM-global defaults#191

Open
testower wants to merge 1 commit intoMobilityData:masterfrom
entur:fix/jsonpath-global-defaults
Open

fix: stop mutating JsonPath JVM-global defaults#191
testower wants to merge 1 commit intoMobilityData:masterfrom
entur:fix/jsonpath-global-defaults

Conversation

@testower
Copy link
Copy Markdown
Collaborator

AbstractVersion's static initializer called Configuration.setDefaults(...) to install JsonOrgJsonProvider as the JVM-wide JsonPath default. Once that class loaded, every other JsonPath user in the same process was forced onto the org.json provider — which only recognises org.json.JSONObject as a map. A consumer using JsonPath against Jackson-parsed maps (e.g. Spring's WebGraphQlTester feeding LinkedHashMap responses to JsonPath) would then fail with PathNotFoundException whenever validator classes happened to load before that consumer first evaluated a path. Class-load order makes the bug intermittent: it surfaces in some test environments but not others.

Replace the global mutation with a SchemaJsonPath facade that exposes a single static parse(Object) returning a DocumentContext bound to a private JsonOrg-configured Configuration. All JsonPath.parse(jsonObject) call sites in AbstractVersion and the rule patchers now route through the facade, so adding a new schema-patching rule cannot accidentally fall back to the default provider.

AbstractVersion's static initializer called Configuration.setDefaults(...)
to install JsonOrgJsonProvider as the JVM-wide JsonPath default. Once that
class loaded, every other JsonPath user in the same process was forced onto
the org.json provider — which only recognises org.json.JSONObject as a map.
A consumer using JsonPath against Jackson-parsed maps (e.g. Spring's
WebGraphQlTester feeding LinkedHashMap responses to JsonPath) would then
fail with PathNotFoundException whenever validator classes happened to load
before that consumer first evaluated a path. Class-load order makes the
bug intermittent: it surfaces in some test environments but not others.

Replace the global mutation with a SchemaJsonPath facade that exposes a
single static parse(Object) returning a DocumentContext bound to a private
JsonOrg-configured Configuration. All JsonPath.parse(jsonObject) call sites
in AbstractVersion and the rule patchers now route through the facade, so
adding a new schema-patching rule cannot accidentally fall back to the
default provider.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant