From dbf8d3b956bb45f5921ccad74311077acd020cca Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 28 Jul 2023 21:00:54 -0700 Subject: [PATCH] Update release notes wrt #1067 --- release-notes/CREDITS-2.x | 5 ++++ release-notes/VERSION-2.x | 2 ++ .../core/ErrorReportConfiguration.java | 30 ++++++++++++++----- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 293f899180..bd64d82f7d 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -382,3 +382,8 @@ Carter Kozak (carterkozak@github) Armin Samii (artoonie@github) * Contributed #1050: Compare `_snapshotInfo` in `Version` (2.16.0) + +Joo Hyuk Kim (JooHyukKim@github) + * Contributed #1067: Add `ErrorReportConfiguration` + (2.16.0) + diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index f9b9aac8c4..635fb4e10c 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -37,6 +37,8 @@ a pure JSON library. (contributed by @artoonie) #1051: Add `JsonGeneratorDecorator` to allow decorating `JsonGenerator`s (contributed by @digulla) +#1067: Add `ErrorReportConfiguration` + (contributed by Joo-Hyuk K) 2.15.2 (30-May-2023) diff --git a/src/main/java/com/fasterxml/jackson/core/ErrorReportConfiguration.java b/src/main/java/com/fasterxml/jackson/core/ErrorReportConfiguration.java index 5ad4c27738..b0145d31e2 100644 --- a/src/main/java/com/fasterxml/jackson/core/ErrorReportConfiguration.java +++ b/src/main/java/com/fasterxml/jackson/core/ErrorReportConfiguration.java @@ -15,7 +15,8 @@ * @since 2.16 */ public class ErrorReportConfiguration - implements Serializable { + implements Serializable +{ private static final long serialVersionUID = 1L; /** @@ -46,6 +47,22 @@ public class ErrorReportConfiguration private static ErrorReportConfiguration DEFAULT = new ErrorReportConfiguration(DEFAULT_MAX_ERROR_TOKEN_LENGTH, DEFAULT_MAX_RAW_CONTENT_LENGTH); + /** + * Override the default ErrorReportConfiguration. These defaults are only used when {@link JsonFactory} + * instances are not configured with their own ErrorReportConfiguration. + *

+ * Library maintainers should not set this as it will affect other code that uses Jackson. + * Library maintainers who want to configure ErrorReportConfiguration for the Jackson usage within their + * lib should create ObjectMapper instances that have a {@link JsonFactory} instance with + * the required ErrorReportConfiguration. + *

+ * This method is meant for users delivering applications. If they use this, they set it when they start + * their application to avoid having other code initialize their mappers before the defaults are overridden. + * + * @param errorReportConfiguration new default for ErrorReportConfiguration (a null value will reset to built-in default) + * @see #defaults() + * @see #builder() + */ public static void overrideDefaultErrorReportConfiguration(final ErrorReportConfiguration errorReportConfiguration) { if (errorReportConfiguration == null) { DEFAULT = new ErrorReportConfiguration(DEFAULT_MAX_ERROR_TOKEN_LENGTH, DEFAULT_MAX_RAW_CONTENT_LENGTH); @@ -78,7 +95,7 @@ public Builder maxErrorTokenLength(final int maxErrorTokenLength) { /** * * @see ErrorReportConfiguration#_maxRawContentLength - * @return This factory instance (to allow call chaining) + * @return This builder instance (to allow call chaining) */ public Builder maxRawContentLength(final int maxRawContentLength) { validateMaxRawContentLength(maxRawContentLength); @@ -129,8 +146,7 @@ public static ErrorReportConfiguration defaults() { } /** - * @return New {@link Builder} initialized with settings of configuration - * instance + * @return New {@link Builder} initialized with settings of configuration instance */ public Builder rebuild() { return new Builder(this); @@ -156,7 +172,7 @@ public int getMaxErrorTokenLength() { * Accessor for {@link #_maxRawContentLength} * * @return Maximum length of token to include in error messages - * @see Builder#maxRawContentLength + * @see Builder#maxRawContentLength(int) */ public int getMaxRawContentLength() { return _maxRawContentLength; @@ -174,14 +190,14 @@ public int getMaxRawContentLength() { * * @param maxErrorTokenLength Maximum length of token to include in error messages */ - private static void validateMaxErrorTokenLength(int maxErrorTokenLength) throws IllegalArgumentException { + 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) { + static void validateMaxRawContentLength(int maxRawContentLength) { if (maxRawContentLength < 0) { throw new IllegalArgumentException( String.format("Value of maxRawContentLength (%d) cannot be negative", maxRawContentLength));