-
-
Notifications
You must be signed in to change notification settings - Fork 818
Make MAX_ERROR_TOKEN_LENGTH configurable via ErrorReportConfiguration
#1043
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
Closed
JooHyukKim
wants to merge
20
commits into
FasterXML:2.16
from
JooHyukKim:Implement-configurable-MAX_ERROR_TOKEN_LENGTH
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fd866d9
Full implmenentation
JooHyukKim 52f5c5c
Clean up IOContenxt diffs
JooHyukKim c000c73
Make test more readable
JooHyukKim 8816e36
Fix Documentation and error message by review
JooHyukKim 478335f
Fix broken test due to error message changed.
JooHyukKim c69ac7d
Implement ErrorTokenConfiguration, object version of MAX_ERROR_TOKEN_…
JooHyukKim 0c1a6ac
Clean up test
JooHyukKim 6152df0
Remove empty line
JooHyukKim 0934d1e
Merge branch '2.16' into Implement-configurable-MAX_ERROR_TOKEN_LENGTH
JooHyukKim bb438dd
Rename to ErrorReportConfiguration
JooHyukKim 3b00a11
Clean up previous ErrorTokenConfig
JooHyukKim 2cae3b4
Implement new ErrorReportConfiguration._maxRawContentLength
JooHyukKim bd3ad8c
Implement ErrorReportConfiguration via construction.
JooHyukKim 1428232
Use ErrorReportConfiguration
JooHyukKim 8d9616b
Merge branch '2.16' into Implement-configurable-MAX_ERROR_TOKEN_LENGTH
JooHyukKim dd7b3f2
Apply review
JooHyukKim d07e9a0
Fix test
JooHyukKim 8684f8b
Add deprecation marker
JooHyukKim 33f3a1c
Remove confusing example
JooHyukKim 230a4ae
Remove faulty default values
JooHyukKim 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
191 changes: 191 additions & 0 deletions
191
src/main/java/com/fasterxml/jackson/core/ErrorReportConfiguration.java
This file contains hidden or 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,191 @@ | ||
| package com.fasterxml.jackson.core; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| /** | ||
| * Container for configuration values used when handling errorneous token inputs. | ||
| * For example, unquoted text segments. | ||
| * <p> | ||
| * Currently default settings are | ||
| * <ul> | ||
| * <li>Maximum length of token to include in error messages (see {@link #_maxErrorTokenLength}) | ||
| * <li>Maximum length of raw content to include in error messages (see {@link #_maxRawContentLength}) | ||
| * </ul> | ||
| * | ||
| * @since 2.16 | ||
| */ | ||
| public class ErrorReportConfiguration | ||
| implements Serializable { | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| /** | ||
| * Default value for {@link #_maxErrorTokenLength}. | ||
| */ | ||
| public static final int DEFAULT_MAX_ERROR_TOKEN_LENGTH = 256; | ||
|
|
||
| /** | ||
| * Previous was {@link com.fasterxml.jackson.core.io.ContentReference#DEFAULT_MAX_CONTENT_SNIPPET}. | ||
| * Default value for {@link #_maxRawContentLength}. | ||
| */ | ||
| public static final int DEFAULT_MAX_RAW_CONTENT_LENGTH = 500; | ||
|
|
||
| /** | ||
| * Maximum length of token to include in error messages | ||
| * | ||
| * @see Builder#maxErrorTokenLength(int) | ||
| */ | ||
| protected final int _maxErrorTokenLength; | ||
|
|
||
| /** | ||
| * Maximum length of raw content to include in error messages | ||
| * | ||
| * @see Builder#maxRawContentLength(int) | ||
| */ | ||
| protected final int _maxRawContentLength; | ||
|
|
||
| private static ErrorReportConfiguration DEFAULT = | ||
| new ErrorReportConfiguration(DEFAULT_MAX_ERROR_TOKEN_LENGTH, DEFAULT_MAX_RAW_CONTENT_LENGTH); | ||
|
|
||
| public static void overrideDefaultErrorReportConfiguration(final ErrorReportConfiguration errorReportConfiguration) { | ||
| if (errorReportConfiguration == null) { | ||
| DEFAULT = new ErrorReportConfiguration(DEFAULT_MAX_ERROR_TOKEN_LENGTH, DEFAULT_MAX_RAW_CONTENT_LENGTH); | ||
| } else { | ||
| DEFAULT = errorReportConfiguration; | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| /********************************************************************** | ||
| /* Builder | ||
| /********************************************************************** | ||
| */ | ||
|
|
||
| public static final class Builder { | ||
| private int maxErrorTokenLength; | ||
| private int maxRawContentLength; | ||
|
|
||
| /** | ||
| * @param maxErrorTokenLength Constraints | ||
| * @return This factory instance (to allow call chaining) | ||
| * @throws IllegalArgumentException if {@code maxErrorTokenLength} is less than 0 | ||
| */ | ||
| public Builder maxErrorTokenLength(final int maxErrorTokenLength) { | ||
| validateMaxErrorTokenLength(maxErrorTokenLength); | ||
| this.maxErrorTokenLength = maxErrorTokenLength; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @see ErrorReportConfiguration#_maxRawContentLength | ||
| * @return This factory instance (to allow call chaining) | ||
| */ | ||
| public Builder maxRawContentLength(final int maxRawContentLength) { | ||
| validateMaxRawContentLength(maxRawContentLength); | ||
| this.maxRawContentLength = maxRawContentLength; | ||
| return this; | ||
| } | ||
|
|
||
| Builder() { | ||
| this(DEFAULT_MAX_ERROR_TOKEN_LENGTH, DEFAULT_MAX_RAW_CONTENT_LENGTH); | ||
| } | ||
|
|
||
| Builder(final int maxErrorTokenLength, final int maxRawContentLength) { | ||
| this.maxErrorTokenLength = maxErrorTokenLength; | ||
| this.maxRawContentLength = maxRawContentLength; | ||
| } | ||
|
|
||
| Builder(ErrorReportConfiguration src) { | ||
| this.maxErrorTokenLength = src._maxErrorTokenLength; | ||
| this.maxRawContentLength = src._maxRawContentLength; | ||
| } | ||
|
|
||
| public ErrorReportConfiguration build() { | ||
| return new ErrorReportConfiguration(maxErrorTokenLength, maxRawContentLength); | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| /********************************************************************** | ||
| /* Life-cycle | ||
| /********************************************************************** | ||
| */ | ||
|
|
||
| protected ErrorReportConfiguration(final int maxErrorTokenLength, final int maxRawContentLength) { | ||
| _maxErrorTokenLength = maxErrorTokenLength; | ||
| _maxRawContentLength = maxRawContentLength; | ||
| } | ||
|
|
||
| public static ErrorReportConfiguration.Builder builder() { | ||
| return new ErrorReportConfiguration.Builder(); | ||
| } | ||
|
|
||
| /** | ||
| * @return the default {@link ErrorReportConfiguration} (when none is set on the {@link JsonFactory} explicitly) | ||
| * @see #overrideDefaultErrorReportConfiguration(ErrorReportConfiguration) | ||
| */ | ||
| public static ErrorReportConfiguration defaults() { | ||
| return DEFAULT; | ||
| } | ||
|
|
||
| /** | ||
| * @return New {@link ErrorReportConfiguration.Builder} initialized with settings of configuration | ||
| * instance | ||
| */ | ||
| public ErrorReportConfiguration.Builder rebuild() { | ||
| return new ErrorReportConfiguration.Builder(this); | ||
| } | ||
|
|
||
| /* | ||
| /********************************************************************** | ||
| /* Accessors | ||
| /********************************************************************** | ||
| */ | ||
|
|
||
| /** | ||
| * Accessor for {@link #_maxErrorTokenLength} | ||
| * | ||
| * @return Maximum length of token to include in error messages | ||
| * @see Builder#maxErrorTokenLength(int) | ||
| */ | ||
| public int getMaxErrorTokenLength() { | ||
| return _maxErrorTokenLength; | ||
| } | ||
|
|
||
| /** | ||
| * Accessor for {@link #_maxRawContentLength} | ||
| * | ||
| * @return Maximum length of token to include in error messages | ||
| * @see Builder#maxRawContentLength | ||
| */ | ||
| public int getMaxRawContentLength() { | ||
| return _maxRawContentLength; | ||
| } | ||
|
|
||
| /* | ||
| /********************************************************************** | ||
| /* Convenience methods for validation | ||
| /********************************************************************** | ||
| */ | ||
|
|
||
| /** | ||
| * Convenience method that can be used verify valid {@link #_maxErrorTokenLength}. | ||
| * If invalid value is passed in, {@link IllegalArgumentException} is thrown. | ||
| * | ||
| * @param maxErrorTokenLength Maximum length of token to include in error messages | ||
| */ | ||
| private static void validateMaxErrorTokenLength(int maxErrorTokenLength) throws IllegalArgumentException { | ||
| if (maxErrorTokenLength < 0) { | ||
| throw new IllegalArgumentException( | ||
| String.format("Value of maxErrorTokenLength (%d) cannot be negative", maxErrorTokenLength)); | ||
| } | ||
| } | ||
|
|
||
| private static void validateMaxRawContentLength(int maxRawContentLength) { | ||
| if (maxRawContentLength < 0) { | ||
| throw new IllegalArgumentException( | ||
| String.format("Value of maxRawContentLength (%d) cannot be negative", maxRawContentLength)); | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.