Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
erosb committed Nov 23, 2023
2 parents d129487 + 1d711f4 commit 81f0b2f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.8.2</version>
<version>3.15.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
9 changes: 6 additions & 3 deletions core/src/main/java/org/everit/json/schema/CombinedSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,12 @@ public CombinedSchema(Builder builder) {
}

private static int compareBySchemaType(Schema lschema, Schema rschema) {
return lschema instanceof CombinedSchema ?
(rschema instanceof CombinedSchema ? 0 : -1) :
(rschema instanceof CombinedSchema ? 1 : 0);
boolean leftSchemaIsCombined = lschema instanceof CombinedSchema;
boolean rightIsCombined = rschema instanceof CombinedSchema;
int defaultRetval = lschema.hashCode() - rschema.hashCode();
return leftSchemaIsCombined ?
(rightIsCombined ? defaultRetval : -1) :
(rightIsCombined ? 1 : defaultRetval);
}

// ensure subschemas of type CombinedSchema are always visited first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.junit.jupiter.api.Assertions.*;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import org.everit.json.schema.BooleanSchema;
Expand All @@ -16,6 +17,7 @@
import org.everit.json.schema.SchemaLocation;
import org.everit.json.schema.StringSchema;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.junit.jupiter.api.Test;

/**
Expand Down Expand Up @@ -75,4 +77,19 @@ public void multipleCombinedSchemasAtTheSameNestingLevel() {
assertEquals(expected, actual);
}

@Test
public void loadTheSameCombinedSeveralTimes() {
JSONObject json = new JSONObject(new JSONTokener("{\"enum\": [\"V1\", \"V2\", \"V3\"],\"type\": \"string\"}"));

for (int i = 0; i < 100000; ++i) {
Schema s0 = SchemaLoader.load(json);
Schema s1 = SchemaLoader.load(json);

System.out.println("Iter: " + i + ", equals=" + Objects.equals(s0, s1));

if (i > 10) {
assertEquals(s0, s1);
}
}
}
}

0 comments on commit 81f0b2f

Please sign in to comment.