This is an automated email from the ASF dual-hosted git repository.
yhu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new 89947fded65 fix jsonToRowTest race condition (#36616)
89947fded65 is described below
commit 89947fded65065c8770a35096f2074c729b239dc
Author: Derrick Williams <[email protected]>
AuthorDate: Mon Nov 3 15:08:39 2025 -0500
fix jsonToRowTest race condition (#36616)
* fix race condition
* update based on comments
---
.../org/apache/beam/sdk/util/RowJsonUtils.java | 31 +++++++++++-----------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git
a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/RowJsonUtils.java
b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/RowJsonUtils.java
index c83048ca8de..ee41d0da28f 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/RowJsonUtils.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/RowJsonUtils.java
@@ -46,26 +46,21 @@ public class RowJsonUtils {
/**
* Increase the default jackson-databind stream read constraint.
*
- * <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>In Jackson 2.15, a new constraint is added on the max string length of
JSON parsing, see
+ * https://github.com/FasterXML/jackson-core/issues/863. The default is 20M
characters. This is
+ * too small for some of our users. This method allows users to increase
this limit.
*/
- public static void increaseDefaultStreamReadConstraints(int newLimit) {
- if (newLimit <= defaultBufferLimit) {
+ public static synchronized void increaseDefaultStreamReadConstraints(int
newLimit) {
+ if (!STREAM_READ_CONSTRAINTS_AVAILABLE) {
return;
}
- try {
- Class<?> unused =
Class.forName("com.fasterxml.jackson.core.StreamReadConstraints");
-
+ if (newLimit > defaultBufferLimit) {
com.fasterxml.jackson.core.StreamReadConstraints.overrideDefaultStreamReadConstraints(
com.fasterxml.jackson.core.StreamReadConstraints.builder()
.maxStringLength(newLimit)
.build());
- } catch (ClassNotFoundException e) {
- // <2.15, do nothing
+ defaultBufferLimit = newLimit;
}
- defaultBufferLimit = newLimit;
}
static {
@@ -103,11 +98,17 @@ public class RowJsonUtils {
*/
public static JsonFactory createJsonFactory(int sizeLimit) {
sizeLimit = Math.max(sizeLimit, MAX_STRING_LENGTH);
- JsonFactory jsonFactory = new JsonFactory();
if (STREAM_READ_CONSTRAINTS_AVAILABLE) {
- StreamReadConstraintsHelper.setStreamReadConstraints(jsonFactory,
sizeLimit);
+ // Synchronize to avoid race condition with
increaseDefaultStreamReadConstraints
+ // which modifies static defaults that builder() and new JsonFactory()
may read.
+ synchronized (RowJsonUtils.class) {
+ JsonFactory jsonFactory = new JsonFactory();
+ StreamReadConstraintsHelper.setStreamReadConstraints(jsonFactory,
sizeLimit);
+ return jsonFactory;
+ }
+ } else {
+ return new JsonFactory();
}
- return jsonFactory;
}
public static ObjectMapper newObjectMapperWith(RowJson.RowJsonDeserializer
deserializer) {