-
Notifications
You must be signed in to change notification settings - Fork 280
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
#302: do not use ReferenceSchema#referredSchema for equals+hashCode #378
Open
tmarsteel
wants to merge
7
commits into
everit-org:master
Choose a base branch
from
rebuy-de:cyclic-schema
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0851cc3
Issue #302: do not use ReferenceSchema#referredSchema for equals+hash…
14ae9d2
#302: fix unit test name naming
2834a61
#302: remove accidentially added jenv config
844d515
Issue #302: include ReferenceSchema#referredSchema in equals
fe1a51c
Issue #302: improve stability of HashCodeRecursionTest
13438c9
Issue #302: DRAFT: support ReferenceSchema#equals with cyclic schemas
631d08d
Issue #302: javadocs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
core/src/test/java/org/everit/json/schema/HashCodeRecursionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.everit.json.schema; | ||
|
||
import org.everit.json.schema.loader.SchemaLoader; | ||
import org.json.JSONObject; | ||
import org.json.JSONTokener; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class HashCodeRecursionTest | ||
{ | ||
@Test | ||
public void hashCodeShouldNotProduceStackoverflowOnCyclicSchema() throws IOException | ||
{ | ||
JSONObject schemaJson; | ||
try (InputStream inStream = getClass().getResourceAsStream("/org/everit/jsonvalidator/cyclic.json")) { | ||
schemaJson = new JSONObject(new JSONTokener(inStream)); | ||
} | ||
|
||
Schema schema = new SchemaLoader.SchemaLoaderBuilder() | ||
.schemaJson(schemaJson) | ||
.build() | ||
.load() | ||
.build(); | ||
|
||
schema.hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
core/src/test/resources/org/everit/jsonvalidator/cyclic.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-06/schema#", | ||
"type": "object", | ||
"title": "Foo Schema", | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/Foo" | ||
} | ||
], | ||
"definitions": { | ||
"Bar": { | ||
"type": "object", | ||
"properties": { | ||
"foo": { | ||
"$ref": "#/definitions/Foo" | ||
} | ||
} | ||
}, | ||
"Foo": { | ||
"type": "object", | ||
"properties": { | ||
"bar": { | ||
"$ref": "#/definitions/Bar" | ||
} | ||
} | ||
} | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @tmarsteel , do you think we loose anything if we keep this line? So my concern is that, with this change, there can be (rare) cases when two schemas are considered equal when they are not (I mean eg. two references pointing to
#
, but this denotes the roots of two different schema documents).What do you think about keeping this line? I see that it might run into infinite
equals()
recursions, but that's probably a very rare case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of Confluent Schema Registry, we call
equals
quite often on schema. So we would prefer the fix above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very good point. The testcase and my actual cyclic schemas both work with
referredSchema
being included in equals.