Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,20 @@ public class RowJsonUtils {
* overwrite the default buffer size limit to 100 MB, and exposes this interface for higher limit.
* If needed, call this method during pipeline run time, e.g. in DoFn.setup.
*/
public static void increaseDefaultStreamReadConstraints(int newLimit) {
if (newLimit <= defaultBufferLimit) {
return;
public static synchronized void increaseDefaultStreamReadConstraints(int newLimit) {
if (newLimit > defaultBufferLimit) {
try {
Class.forName("com.fasterxml.jackson.core.StreamReadConstraints");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can check STREAM_READ_CONSTRAINTS_AVAILABLE then return early and remove this try {} block


com.fasterxml.jackson.core.StreamReadConstraints.overrideDefaultStreamReadConstraints(
com.fasterxml.jackson.core.StreamReadConstraints.builder()
.maxStringLength(newLimit)
.build());
} catch (ClassNotFoundException e) {
// <2.15, do nothing
}
defaultBufferLimit = newLimit;
}
try {
Class<?> unused = Class.forName("com.fasterxml.jackson.core.StreamReadConstraints");

com.fasterxml.jackson.core.StreamReadConstraints.overrideDefaultStreamReadConstraints(
com.fasterxml.jackson.core.StreamReadConstraints.builder()
.maxStringLength(newLimit)
.build());
} catch (ClassNotFoundException e) {
// <2.15, do nothing
}
defaultBufferLimit = newLimit;
}

static {
Expand Down Expand Up @@ -101,7 +100,7 @@ static void setStreamReadConstraints(JsonFactory jsonFactory, int sizeLimit) {
* factory to higher limits. If needed, call this method during pipeline run time, e.g. in
* DoFn.setup. This avoids a data race caused by modifying the global default settings.
*/
public static JsonFactory createJsonFactory(int sizeLimit) {
public static synchronized JsonFactory createJsonFactory(int sizeLimit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we confine synchronize {} block only around StreamReadConstraintsHelper.setStreamReadConstraints?

sizeLimit = Math.max(sizeLimit, MAX_STRING_LENGTH);
JsonFactory jsonFactory = new JsonFactory();
if (STREAM_READ_CONSTRAINTS_AVAILABLE) {
Expand Down
Loading