derrickaw commented on code in PR #36073: URL: https://github.com/apache/beam/pull/36073#discussion_r2325857949
########## sdks/java/core/src/main/java/org/apache/beam/sdk/util/RowJsonUtils.java: ########## @@ -34,43 +35,41 @@ @Internal public class RowJsonUtils { - // - private static int defaultBufferLimit; + // The maximum string length for the JSON parser, set to 100 MB. + public static final int MAX_STRING_LENGTH = 100 * 1024 * 1024; /** - * Increase the default jackson-databind stream read constraint. + * Creates a thread-safe JsonFactory with custom stream read constraints. * - * <p>StreamReadConstraints was introduced in jackson 2.15 causing string > 20MB (5MB in 2.15.0) - * parsing failure. This has caused regressions in its dependencies include Beam. Here we - * 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. + * <p>This method encapsulates the logic to increase the default jackson-databind stream read + * constraint to 100MB. This functionality was introduced in Jackson 2.15 causing string > 20MB + * (5MB in <2.15.0) parsing failure. This has caused regressions in its dependencies including + * Beam. Here we create a streamReadConstraints minimum size limit set to 100MB and exposing the + * 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 void increaseDefaultStreamReadConstraints(int newLimit) { - if (newLimit <= defaultBufferLimit) { - return; - } + public static JsonFactory createJsonFactory(int sizeLimit) { + sizeLimit = Math.max(sizeLimit, MAX_STRING_LENGTH); + JsonFactory jsonFactory = new JsonFactory(); try { - Class<?> unused = Class.forName("com.fasterxml.jackson.core.StreamReadConstraints"); - - com.fasterxml.jackson.core.StreamReadConstraints.overrideDefaultStreamReadConstraints( + // Check if StreamReadConstraints is available (Jackson 2.15+) + Class.forName("com.fasterxml.jackson.core.StreamReadConstraints"); + com.fasterxml.jackson.core.StreamReadConstraints streamReadConstraints = com.fasterxml.jackson.core.StreamReadConstraints.builder() - .maxStringLength(newLimit) - .build()); + .maxStringLength(MAX_STRING_LENGTH) Review Comment: good catch, thanks -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@beam.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org