Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not using exceptions for flow control if suppress exceptions is enabled #775

Merged
merged 1 commit into from
Dec 22, 2021

Conversation

r0goyal
Copy link
Contributor

@r0goyal r0goyal commented Dec 8, 2021

No description provided.

@r0goyal r0goyal changed the title Not using exceptions for flow control Not using exceptions for flow control if suppress exceptions is enabled Dec 8, 2021
@r0goyal
Copy link
Contributor Author

r0goyal commented Dec 8, 2021

@kallestenflo Requesting your approval for this

@kallestenflo kallestenflo merged commit b14341a into json-path:master Dec 22, 2021
@abelsromero
Copy link

This has introduced breaking changes in 2.7.0 vs 2.6.0. For instance now set throws and exception when the path is not present in the target JSON.
I can't find any explanation of why this change was introduced or whether the project follows semantic versioning, so I'd really appreciate some clarification on those topics 🙇

@ailjushkin
Copy link

ailjushkin commented Jul 15, 2022

@r0goyal @abelsromero Maybe we should add an option to create an absent path, to handle each of use cases. But at least I'd wanted to get any ideas of what exact problem this PR solves to get more context on this.

@jslopez-forum
Copy link

jslopez-forum commented Nov 6, 2022

I found another change in behavior from this change. The following snippet used to return null under 2.6.0 and it now fails under 2.7.0. Since SUPPRESS_EXCEPTIONS is configured, I would have expected no exceptions to be propagated.

        final String json = "{\"value\" :  null}";
        final Configuration configuration = Configuration.builder()
                .jsonProvider(new JsonOrgJsonProvider())
                .mappingProvider(new JsonOrgMappingProvider())
                .options(Option.SUPPRESS_EXCEPTIONS).build();
        String value = JsonPath.using(configuration).parse(json).read("$.value");
        System.out.println(value);

2.6.0 value = null
2.7.0

Exception in thread "main" com.jayway.jsonpath.JsonPathException: org.json.JSONException: JSONArray[0] not found.
	at com.jayway.jsonpath.spi.json.JsonOrgJsonProvider.getArrayIndex(JsonOrgJsonProvider.java:75)
	at com.jayway.jsonpath.internal.path.EvaluationContextImpl.getValue(EvaluationContextImpl.java:145)
	at com.jayway.jsonpath.JsonPath.read(JsonPath.java:199)
	at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:88)
	at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:77)
	at Scratch.main(scratch_1.java:15)
Caused by: org.json.JSONException: JSONArray[0] not found.
	at org.json.JSONArray.get(JSONArray.java:209)
	at com.jayway.jsonpath.spi.json.JsonOrgJsonProvider.getArrayIndex(JsonOrgJsonProvider.java:73)
	... 5 more

@abelsromero
Copy link

My main concern with this is the "surprise factor" at the end of the day, we dealt with it, but after some head bashing.
Being blunt here, apologies in advance, "are breaking changes possible in any version release?"

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.

None yet

5 participants