Skip to content

Commit e33efb3

Browse files
committed
Update release notes wrt #1081; minor comment clean up
1 parent 4fd8c85 commit e33efb3

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

release-notes/CREDITS-2.x

+4
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,7 @@ Joo Hyuk Kim (JooHyukKim@github)
387387
* Contributed #1067: Add `ErrorReportConfiguration`
388388
(2.16.0)
389389

390+
David Schlosnagle (@schlosna)
391+
* Contributed #1081: Make `ByteSourceJsonBootstrapper` use `StringReader` for < 8KiB
392+
byte[] inputs
393+
(2.16.0)

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ a pure JSON library.
3939
(contributed by @digulla)
4040
#1066: Add configurable error report behavior via `ErrorReportConfiguration`
4141
(contributed by Joo-Hyuk K)
42+
#1081: Make `ByteSourceJsonBootstrapper` use `StringReader` for < 8KiB byte[] inputs
43+
(contributed by @schlosna)
4244

4345
2.15.2 (30-May-2023)
4446

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

+12-13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.fasterxml.jackson.core.io.*;
99
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
1010
import com.fasterxml.jackson.core.sym.CharsToNameCanonicalizer;
11+
import com.fasterxml.jackson.core.util.VersionUtil;
1112

1213
/**
1314
* This class is used to determine the encoding of byte stream
@@ -22,7 +23,7 @@ public final class ByteSourceJsonBootstrapper
2223
public final static byte UTF8_BOM_2 = (byte) 0xBB;
2324
public final static byte UTF8_BOM_3 = (byte) 0xBF;
2425

25-
// [jackson-core#488] Limit in bytes for input byte array length to use StringReader instead of InputStreamReader
26+
// [jackson-core#1081] Limit in bytes for input byte array length to use StringReader instead of InputStreamReader
2627
private static final int STRING_READER_BYTE_ARRAY_LENGTH_LIMIT = 8192;
2728

2829
/*
@@ -175,7 +176,8 @@ public JsonEncoding detectEncoding() throws IOException
175176
break;
176177
case 4: enc = _bigEndian ? JsonEncoding.UTF32_BE : JsonEncoding.UTF32_LE;
177178
break;
178-
default: throw new RuntimeException("Internal error"); // should never get here
179+
default:
180+
return VersionUtil.throwInternalReturnAny();
179181
}
180182
}
181183
_context.setEncoding(enc);
@@ -235,15 +237,14 @@ public Reader constructReader() throws IOException
235237
if (in == null) {
236238
int length = _inputEnd - _inputPtr;
237239
if (length <= STRING_READER_BYTE_ARRAY_LENGTH_LIMIT) {
238-
// [jackson-core#488] Avoid overhead of heap ByteBuffer allocated by InputStreamReader
240+
// [jackson-core#1081] Avoid overhead of heap ByteBuffer allocated by InputStreamReader
239241
// when processing small inputs up to 8KiB.
240242
return new StringReader(new String(_inputBuffer, _inputPtr, length, enc.getJavaName()));
241243
}
242244
in = new ByteArrayInputStream(_inputBuffer, _inputPtr, _inputEnd);
243245
} else {
244-
/* Also, if we have any read but unused input (usually true),
245-
* need to merge that input in:
246-
*/
246+
// Also, if we have any read but unused input (usually true),
247+
// need to merge that input in:
247248
if (_inputPtr < _inputEnd) {
248249
in = new MergedStream(_context, in, _inputBuffer, _inputPtr, _inputEnd);
249250
}
@@ -254,7 +255,7 @@ public Reader constructReader() throws IOException
254255
return new UTF32Reader(_context, _in, _inputBuffer, _inputPtr, _inputEnd,
255256
_context.getEncoding().isBigEndian());
256257
}
257-
throw new RuntimeException("Internal error"); // should never get here
258+
return VersionUtil.throwInternalReturnAny();
258259
}
259260

260261
public JsonParser constructParser(int parserFeatures, ObjectCodec codec,
@@ -266,9 +267,8 @@ public JsonParser constructParser(int parserFeatures, ObjectCodec codec,
266267
int bytesProcessed = _inputPtr - prevInputPtr;
267268

268269
if (enc == JsonEncoding.UTF8) {
269-
/* and without canonicalization, byte-based approach is not performant; just use std UTF-8 reader
270-
* (which is ok for larger input; not so hot for smaller; but this is not a common case)
271-
*/
270+
// and without canonicalization, byte-based approach is not performant; just use std UTF-8 reader
271+
// (which is ok for larger input; not so hot for smaller; but this is not a common case)
272272
if (JsonFactory.Feature.CANONICALIZE_FIELD_NAMES.enabledIn(factoryFeatures)) {
273273
ByteQuadsCanonicalizer can = rootByteSymbols.makeChild(factoryFeatures);
274274
return new UTF8StreamJsonParser(_context, parserFeatures, _in, codec, can,
@@ -535,9 +535,8 @@ private void reportWeirdUCS4(String type) throws IOException {
535535
*/
536536

537537
protected boolean ensureLoaded(int minimum) throws IOException {
538-
/* Let's assume here buffer has enough room -- this will always
539-
* be true for the limited used this method gets
540-
*/
538+
// Let's assume here buffer has enough room -- this will always
539+
// be true for the limited used this method gets
541540
int gotten = (_inputEnd - _inputPtr);
542541
while (gotten < minimum) {
543542
int count;

src/main/java/com/fasterxml/jackson/core/util/VersionUtil.java

+4
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,8 @@ private final static void _close(Closeable c) {
175175
public final static void throwInternal() {
176176
throw new RuntimeException("Internal error: this code path should never get executed");
177177
}
178+
179+
public final static <T> T throwInternalReturnAny() {
180+
throw new RuntimeException("Internal error: this code path should never get executed");
181+
}
178182
}

0 commit comments

Comments
 (0)