Skip to content

Commit 1f7cef9

Browse files
authored
Retrofit IOContext with ErrorReportConfiguration (#1068)
1 parent 55f47b7 commit 1f7cef9

File tree

5 files changed

+48
-15
lines changed

5 files changed

+48
-15
lines changed

src/main/java/com/fasterxml/jackson/core/base/ParserMinimalBase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ public abstract class ParserMinimalBase extends JsonParser
128128
* as part of error messages.
129129
*
130130
* @since 2.9
131+
* @deprecated Since 2.16. {@link ErrorReportConfiguration#getMaxErrorTokenLength()} will be used instead.
131132
*/
133+
@Deprecated
132134
protected final static int MAX_ERROR_TOKEN_LENGTH = 256;
133135

134136
/*

src/main/java/com/fasterxml/jackson/core/io/IOContext.java

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.core.io;
22

3+
import com.fasterxml.jackson.core.ErrorReportConfiguration;
34
import com.fasterxml.jackson.core.JsonEncoding;
45
import com.fasterxml.jackson.core.StreamReadConstraints;
56
import com.fasterxml.jackson.core.StreamWriteConstraints;
@@ -68,6 +69,11 @@ public class IOContext
6869
*/
6970
protected final StreamReadConstraints _streamReadConstraints;
7071

72+
/**
73+
* @since 2.16
74+
*/
75+
protected final ErrorReportConfiguration _errorReportConfiguration;
76+
7177
/**
7278
* @since 2.16
7379
*/
@@ -129,18 +135,38 @@ public class IOContext
129135
* @param managedResource Whether input source is managed (owned) by Jackson library
130136
*
131137
* @since 2.16
138+
* @deprecated Since 2.16, use {@link #IOContext(StreamReadConstraints, StreamWriteConstraints, BufferRecycler,
139+
* ContentReference, boolean, ErrorReportConfiguration)} instead.
132140
*/
141+
@Deprecated
133142
public IOContext(StreamReadConstraints src, StreamWriteConstraints swc, BufferRecycler br,
134143
ContentReference contentRef, boolean managedResource)
135144
{
136-
_streamReadConstraints = (src == null) ?
137-
StreamReadConstraints.defaults() : src;
138-
_streamWriteConstraints = (swc == null) ?
139-
StreamWriteConstraints.defaults() : swc;
145+
this(src, swc, br, contentRef, managedResource, ErrorReportConfiguration.defaults());
146+
}
147+
148+
/**
149+
* Main constructor to use.
150+
*
151+
* @param src constraints for streaming reads
152+
* @param swc constraints for streaming writes
153+
* @param br BufferRecycler to use, if any ({@code null} if none)
154+
* @param contentRef Input source reference for location reporting
155+
* @param managedResource Whether input source is managed (owned) by Jackson library
156+
* @param erc Error report configuration to use
157+
*
158+
* @since 2.16
159+
*/
160+
public IOContext(StreamReadConstraints src, StreamWriteConstraints swc, BufferRecycler br,
161+
ContentReference contentRef, boolean managedResource, ErrorReportConfiguration erc)
162+
{
163+
_streamReadConstraints = src;
164+
_streamWriteConstraints = swc;
140165
_bufferRecycler = br;
141166
_contentReference = contentRef;
142167
_sourceRef = contentRef.getRawContent();
143168
_managedResource = managedResource;
169+
_errorReportConfiguration = erc;
144170
}
145171

146172
/**
@@ -150,19 +176,14 @@ public IOContext(StreamReadConstraints src, StreamWriteConstraints swc, BufferRe
150176
* @param managedResource Whether input source is managed (owned) by Jackson library
151177
*
152178
* @since 2.15
153-
* @deprecated use v2.16 constructor with additional <code>StreamWriteConstraints</code>
179+
* @deprecated Since 2.16. Use {@link #IOContext(StreamReadConstraints, StreamWriteConstraints, BufferRecycler,
180+
* ContentReference, boolean, ErrorReportConfiguration)} instead.
154181
*/
155182
@Deprecated
156183
public IOContext(StreamReadConstraints src, BufferRecycler br,
157184
ContentReference contentRef, boolean managedResource)
158185
{
159-
_streamReadConstraints = (src == null) ?
160-
StreamReadConstraints.defaults() : src;
161-
_streamWriteConstraints = StreamWriteConstraints.defaults();
162-
_bufferRecycler = br;
163-
_contentReference = contentRef;
164-
_sourceRef = contentRef.getRawContent();
165-
_managedResource = managedResource;
186+
this(src, StreamWriteConstraints.defaults(), br, contentRef, managedResource, ErrorReportConfiguration.defaults());
166187
}
167188

168189
/**
@@ -199,6 +220,16 @@ public StreamWriteConstraints streamWriteConstraints() {
199220
return _streamWriteConstraints;
200221
}
201222

223+
/**
224+
* @return Configured {@link ErrorReportConfiguration}, containing configured values for
225+
* handling error reporting.
226+
*
227+
* @since 2.16
228+
*/
229+
public ErrorReportConfiguration errorReportConfiguration() {
230+
return _errorReportConfiguration;
231+
}
232+
202233
public void setEncoding(JsonEncoding enc) {
203234
_encoding = enc;
204235
}

src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3033,7 +3033,7 @@ protected void _reportInvalidToken(String matchedPart, String msg) throws IOExce
30333033
}
30343034
++_inputPtr;
30353035
sb.append(c);
3036-
if (sb.length() >= MAX_ERROR_TOKEN_LENGTH) {
3036+
if (sb.length() >= _ioContext.errorReportConfiguration().getMaxErrorTokenLength()) {
30373037
sb.append("...");
30383038
break;
30393039
}

src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3691,7 +3691,7 @@ protected void _reportInvalidToken(String matchedPart, String msg) throws IOExce
36913691
break;
36923692
}
36933693
sb.append(c);
3694-
if (sb.length() >= MAX_ERROR_TOKEN_LENGTH) {
3694+
if (sb.length() >= _ioContext.errorReportConfiguration().getMaxErrorTokenLength()) {
36953695
sb.append("...");
36963696
break;
36973697
}

src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingUtf8JsonParserBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ protected JsonToken _finishErrorToken() throws IOException
12441244
// 11-Jan-2016, tatu: note: we will fully consume the character,
12451245
// included or not, so if recovery was possible, it'd be off-by-one...
12461246
_textBuffer.append(ch);
1247-
if (_textBuffer.size() < MAX_ERROR_TOKEN_LENGTH) {
1247+
if (_textBuffer.size() < _ioContext.errorReportConfiguration().getMaxErrorTokenLength()) {
12481248
continue;
12491249
}
12501250
}

0 commit comments

Comments
 (0)