-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
omitting stacktraces for internal exceptions
The purpose of this change is to avoid stacktrace generation for most `ValidationException` instances, since it can come with significant performance improvements in some usecases, see #318 . An `InternalValidationException` is introduced which is a subclass of `ValidationException` but it omits the stacktrace generation by overriding `fillInStackTrace()` to be no-op. This is now thrown everywhere internally. At the end of the validation process the `DefaultValidator` catches the possibly thrown `InternalValidationException` and copies it into a `ValidationInstance` and throws it, so from the caller point of view an exception with a proper stacktrace is thrown. This "public" `ValidationException` is necessary to avoid any potential BC breaks. Tests updated. A good number of unittests and all of the integration tests verify that only root exceptions (and no causing exceptions) have non-empty stacktraces. There is some code duplication between the unit and integ test codebase, this is to be cleaned up a bit in the future (needs a separate testutil module which can be depended on by both `core` and `tests/vanilla`).
- Loading branch information
Showing
13 changed files
with
133 additions
and
23 deletions.
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
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
30 changes: 30 additions & 0 deletions
30
core/src/main/java/org/everit/json/schema/InternalValidationException.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,30 @@ | ||
package org.everit.json.schema; | ||
|
||
import java.util.List; | ||
|
||
class InternalValidationException extends ValidationException { | ||
|
||
InternalValidationException(Schema violatedSchema, Class<?> expectedType, Object actualValue) { | ||
super(violatedSchema, expectedType, actualValue); | ||
} | ||
|
||
InternalValidationException(Schema violatedSchema, Class<?> expectedType, Object actualValue, String keyword, | ||
String schemaLocation) { | ||
super(violatedSchema, expectedType, actualValue, keyword, schemaLocation); | ||
} | ||
|
||
InternalValidationException(Schema violatedSchema, String message, String keyword, String schemaLocation) { | ||
super(violatedSchema, message, keyword, schemaLocation); | ||
} | ||
|
||
InternalValidationException(Schema violatedSchema, StringBuilder pointerToViolation, String message, | ||
List<ValidationException> causingExceptions, String keyword, String schemaLocation) { | ||
super(violatedSchema, pointerToViolation, message, causingExceptions, keyword, schemaLocation); | ||
} | ||
|
||
@Override | ||
public synchronized Throwable fillInStackTrace() { | ||
return this; | ||
} | ||
|
||
} |
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
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
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
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
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
17 changes: 17 additions & 0 deletions
17
core/src/test/java/org/everit/json/schema/InternalValidationExceptionTest.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,17 @@ | ||
package org.everit.json.schema; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
public class InternalValidationExceptionTest { | ||
|
||
@Test | ||
public void stackTraceShouldBeEmpty() { | ||
try { | ||
throw new InternalValidationException(BooleanSchema.INSTANCE, "message", "keyword", "#"); | ||
} catch (ValidationException e) { | ||
assertEquals(0, e.getStackTrace().length); | ||
} | ||
} | ||
} |
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
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
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
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