Skip to content

Commit

Permalink
Merge branch '2.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 1, 2023
2 parents 938251c + 1f7cef9 commit 8ffb4a2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
6 changes: 0 additions & 6 deletions src/main/java/tools/jackson/core/base/ParserMinimalBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ public abstract class ParserMinimalBase extends JsonParser
/**********************************************************************
*/

/**
* Maximum number of characters to include in token reported
* as part of error messages.
*/
protected final static int MAX_ERROR_TOKEN_LENGTH = 256;

protected final static int STREAM_READ_FEATURE_DEFAULTS = StreamReadFeature.collectDefaults();

/*
Expand Down
34 changes: 28 additions & 6 deletions src/main/java/tools/jackson/core/io/IOContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Objects;

import tools.jackson.core.ErrorReportConfiguration;
import tools.jackson.core.JsonEncoding;
import tools.jackson.core.StreamReadConstraints;
import tools.jackson.core.StreamWriteConstraints;
Expand Down Expand Up @@ -59,6 +60,8 @@ public class IOContext

protected final StreamWriteConstraints _streamWriteConstraints;

protected final ErrorReportConfiguration _errorReportConfiguration;

/**
* Reference to the allocated I/O buffer for low-level input reading,
* if any allocated.
Expand Down Expand Up @@ -108,26 +111,37 @@ public class IOContext
/**
* Main constructor to use.
*
* @param streamReadConstraints constraints for streaming reads
* @param streamWriteConstraints constraints for streaming writes
* @param src Constraints for streaming reads
* @param swc Constraints for streaming writes
* @param erc Configuration for error reporting
* @param br BufferRecycler to use, if any ({@code null} if none)
* @param contentRef Input source reference for location reporting
* @param managedResource Whether input source is managed (owned) by Jackson library
* @param enc Encoding in use
*/
public IOContext(StreamReadConstraints streamReadConstraints,
StreamWriteConstraints streamWriteConstraints,
public IOContext(StreamReadConstraints src, StreamWriteConstraints swc,
ErrorReportConfiguration erc,
BufferRecycler br, ContentReference contentRef, boolean managedResource,
JsonEncoding enc)
{
_streamReadConstraints = Objects.requireNonNull(streamReadConstraints);
_streamWriteConstraints = Objects.requireNonNull(streamWriteConstraints);
_streamReadConstraints = Objects.requireNonNull(src);
_streamWriteConstraints = Objects.requireNonNull(swc);
_errorReportConfiguration = Objects.requireNonNull(erc);
_bufferRecycler = br;
_contentReference = contentRef;
_managedResource = managedResource;
_encoding = enc;
}

@Deprecated
public IOContext(StreamReadConstraints src, StreamWriteConstraints swc,
BufferRecycler br, ContentReference contentRef, boolean managedResource,
JsonEncoding enc)
{
this(src, swc, ErrorReportConfiguration.defaults(),
br, contentRef, managedResource, enc);
}

/**
* @return constraints for streaming reads
*/
Expand All @@ -142,6 +156,14 @@ public StreamWriteConstraints streamWriteConstraints() {
return _streamWriteConstraints;
}

/**
* @return Configured {@link ErrorReportConfiguration}, containing configured values for
* handling error reporting.
*/
public ErrorReportConfiguration errorReportConfiguration() {
return _errorReportConfiguration;
}

public IOContext setEncoding(JsonEncoding enc) {
_encoding = enc;
return this;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/tools/jackson/core/json/JsonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ public JsonParser createNonBlockingByteBufferParser(ObjectReadContext readCtxt)
}

protected IOContext _createNonBlockingContext(Object srcRef) {
return new IOContext(_streamReadConstraints, _streamWriteConstraints, _getBufferRecycler(),
return new IOContext(_streamReadConstraints, _streamWriteConstraints,
_getBufferRecycler(),
ContentReference.rawReference(srcRef), false, JsonEncoding.UTF8);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3009,7 +3009,7 @@ protected void _reportInvalidToken(String matchedPart, String msg) throws Jackso
}
++_inputPtr;
sb.append(c);
if (sb.length() >= MAX_ERROR_TOKEN_LENGTH) {
if (sb.length() >= _ioContext.errorReportConfiguration().getMaxErrorTokenLength()) {
sb.append("...");
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3990,7 +3990,7 @@ protected <T> T _reportInvalidToken(String matchedPart, String msg) throws Jacks
break;
}
sb.append(c);
if (sb.length() >= MAX_ERROR_TOKEN_LENGTH) {
if (sb.length() >= _ioContext.errorReportConfiguration().getMaxErrorTokenLength()) {
sb.append("...");
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ protected JsonToken _finishErrorToken() throws JacksonException
// 11-Jan-2016, tatu: note: we will fully consume the character,
// included or not, so if recovery was possible, it'd be off-by-one...
_textBuffer.append(ch);
if (_textBuffer.size() < MAX_ERROR_TOKEN_LENGTH) {
if (_textBuffer.size() < _ioContext.errorReportConfiguration().getMaxErrorTokenLength()) {
continue;
}
}
Expand Down

0 comments on commit 8ffb4a2

Please sign in to comment.