@@ -730,6 +730,7 @@ public void validate(ExecutionContext executionContext, JsonNode jsonNode, JsonN
730730// System.out.println("MISMATCH NEW: " + newEvaluationPath);
731731// System.out.println("-----------------");
732732// }
733+ List <KeywordValidator > validators = getValidators (); // Load the validators before checking the flags
733734 executionContext .evaluationSchema .addLast (this );
734735 boolean unevaluatedPropertiesPresent = executionContext .unevaluatedPropertiesPresent ;
735736 boolean unevaluatedItemsPresent = executionContext .unevaluatedItemsPresent ;
@@ -741,7 +742,7 @@ public void validate(ExecutionContext executionContext, JsonNode jsonNode, JsonN
741742 }
742743 try {
743744 int currentErrors = executionContext .getErrors ().size ();
744- for (KeywordValidator v : getValidators () ) {
745+ for (KeywordValidator v : validators ) {
745746 executionContext .evaluationPath .addLast (v .getKeyword ());
746747 executionContext .evaluationSchemaPath .addLast (v .getKeyword ());
747748 try {
@@ -1626,29 +1627,47 @@ private <T> T walkAtNodeInternal(ExecutionContext executionContext, JsonNode nod
16261627 public void walk (ExecutionContext executionContext , JsonNode node , JsonNode rootNode ,
16271628 NodePath instanceLocation , boolean shouldValidateSchema ) {
16281629 // Walk through all the JSONWalker's.
1629- int currentErrors = executionContext .getErrors ().size ();
1630- for (KeywordValidator validator : getValidators ()) {
1631- NodePath evaluationPathWithKeyword = validator .getEvaluationPath ();
1632- try {
1633- // Call all the pre-walk listeners. If at least one of the pre walk listeners
1634- // returns SKIP, then skip the walk.
1635- if (executionContext .getWalkConfig ().getKeywordWalkListenerRunner ().runPreWalkListeners (executionContext ,
1636- evaluationPathWithKeyword .getName (-1 ), node , rootNode , instanceLocation ,
1637- this , validator )) {
1638- executionContext .evaluationPath .addLast (validator .getKeyword ());
1639- try {
1640- validator .walk (executionContext , node , rootNode , instanceLocation , shouldValidateSchema );
1641- } finally {
1642- executionContext .evaluationPath .removeLast ();
1630+ List <KeywordValidator > validators = getValidators (); // Load the validators before checking the flags
1631+ executionContext .evaluationSchema .addLast (this );
1632+ boolean unevaluatedPropertiesPresent = executionContext .unevaluatedPropertiesPresent ;
1633+ boolean unevaluatedItemsPresent = executionContext .unevaluatedItemsPresent ;
1634+ if (this .unevaluatedPropertiesPresent ) {
1635+ executionContext .unevaluatedPropertiesPresent = this .unevaluatedPropertiesPresent ;
1636+ }
1637+ if (this .unevaluatedItemsPresent ) {
1638+ executionContext .unevaluatedItemsPresent = this .unevaluatedItemsPresent ;
1639+ }
1640+ try {
1641+ int currentErrors = executionContext .getErrors ().size ();
1642+ for (KeywordValidator validator : validators ) {
1643+ NodePath evaluationPathWithKeyword = validator .getEvaluationPath ();
1644+ try {
1645+ // Call all the pre-walk listeners. If at least one of the pre walk listeners
1646+ // returns SKIP, then skip the walk.
1647+ if (executionContext .getWalkConfig ().getKeywordWalkListenerRunner ().runPreWalkListeners (executionContext ,
1648+ evaluationPathWithKeyword .getName (-1 ), node , rootNode , instanceLocation ,
1649+ this , validator )) {
1650+ executionContext .evaluationPath .addLast (validator .getKeyword ());
1651+ executionContext .evaluationSchemaPath .addLast (validator .getKeyword ());
1652+ try {
1653+ validator .walk (executionContext , node , rootNode , instanceLocation , shouldValidateSchema );
1654+ } finally {
1655+ executionContext .evaluationPath .removeLast ();
1656+ executionContext .evaluationSchemaPath .removeLast ();
1657+ }
16431658 }
1659+ } finally {
1660+ // Call all the post-walk listeners.
1661+ executionContext .getWalkConfig ().getKeywordWalkListenerRunner ().runPostWalkListeners (executionContext ,
1662+ evaluationPathWithKeyword .getName (-1 ), node , rootNode , instanceLocation ,
1663+ this , validator ,
1664+ executionContext .getErrors ().subList (currentErrors , executionContext .getErrors ().size ()));
16441665 }
1645- } finally {
1646- // Call all the post-walk listeners.
1647- executionContext .getWalkConfig ().getKeywordWalkListenerRunner ().runPostWalkListeners (executionContext ,
1648- evaluationPathWithKeyword .getName (-1 ), node , rootNode , instanceLocation ,
1649- this , validator ,
1650- executionContext .getErrors ().subList (currentErrors , executionContext .getErrors ().size ()));
16511666 }
1667+ } finally {
1668+ executionContext .evaluationSchema .removeLast ();
1669+ executionContext .unevaluatedPropertiesPresent = unevaluatedPropertiesPresent ;
1670+ executionContext .unevaluatedItemsPresent = unevaluatedItemsPresent ;
16521671 }
16531672 }
16541673
0 commit comments