gemini-code-assist[bot] commented on code in PR #38531:
URL: https://github.com/apache/beam/pull/38531#discussion_r3262325401


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java:
##########
@@ -1733,7 +1726,15 @@ private static JsonDeserializer<Object> 
computeDeserializerForMethod(Method meth
       BeanProperty prop = createBeanProperty(method);
       AnnotatedMember annotatedMethod = prop.getMember();
 
-      DefaultDeserializationContext context = DESERIALIZATION_CONTEXT.copy();
+      // Initialize a new context that is properly associated with a dummy 
parser.
+      // Using copy() here would leave the context's transient parser field as 
null,
+      // causing NullPointerExceptions in Jackson 2.14+ when deserializers try 
to
+      // query the parser for format constraints or coercion validations.
+      JsonParser dummyParser = new TokenBuffer(MAPPER, false).asParser();
+      DefaultDeserializationContext context =
+          ((DefaultDeserializationContext) MAPPER.getDeserializationContext())
+              .createInstance(
+                  MAPPER.getDeserializationConfig(), dummyParser, new 
InjectableValues.Std());

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Use the suggested helper method to create the context and reduce duplication.
   
   ```suggestion
         // Initialize a new context that is properly associated with a dummy 
parser.
         // Using copy() here would leave the context's transient parser field 
as null,
         // causing NullPointerExceptions in Jackson 2.14+ when deserializers 
try to
         // query the parser for format constraints or coercion validations.
         JsonParser dummyParser = new TokenBuffer(MAPPER, false).asParser();
         DefaultDeserializationContext context = 
createDeserializationContext(dummyParser);
   ```



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java:
##########
@@ -502,13 +502,6 @@ Class<T> getProxyClass() {
       new ObjectMapper()
           
.registerModules(ObjectMapper.findModules(ReflectHelpers.findClassLoader()));
 
-  private static final DefaultDeserializationContext DESERIALIZATION_CONTEXT =
-      new 
DefaultDeserializationContext.Impl(MAPPER.getDeserializationContext().getFactory())
-          .createInstance(
-              MAPPER.getDeserializationConfig(),
-              new TokenBuffer(MAPPER, false).asParser(),
-              new InjectableValues.Std());
-
   static final DefaultSerializerProvider SERIALIZER_PROVIDER =
       new DefaultSerializerProvider.Impl()
           .createInstance(MAPPER.getSerializationConfig(), 
MAPPER.getSerializerFactory());

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The logic for creating a `DefaultDeserializationContext` with a parser and 
injectable values is now duplicated in multiple places. Consider centralizing 
this into a helper method to improve maintainability and reduce boilerplate.
   
   ```suggestion
     static final DefaultSerializerProvider SERIALIZER_PROVIDER =
         new DefaultSerializerProvider.Impl()
             .createInstance(MAPPER.getSerializationConfig(), 
MAPPER.getSerializerFactory());
   
     private static DefaultDeserializationContext 
createDeserializationContext(JsonParser parser) {
       return ((DefaultDeserializationContext) 
MAPPER.getDeserializationContext())
           .createInstance(MAPPER.getDeserializationConfig(), parser, new 
InjectableValues.Std());
     }
   ```



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java:
##########
@@ -1805,7 +1806,14 @@ static Object deserializeNode(JsonNode node, Method 
method) throws IOException {
     parser.nextToken();
 
     JsonDeserializer<Object> jsonDeserializer = 
getDeserializerForMethod(method);
-    return jsonDeserializer.deserialize(parser, 
DESERIALIZATION_CONTEXT.copy());
+    // Create a fresh context that is correctly associated with the active 
parser.
+    // Using copy() here would leave the context's transient parser field as 
null,
+    // causing NullPointerExceptions in Jackson 2.14+ deserializers during 
coercion
+    // validations and length checks.
+    DefaultDeserializationContext context =
+        ((DefaultDeserializationContext) MAPPER.getDeserializationContext())
+            .createInstance(MAPPER.getDeserializationConfig(), parser, new 
InjectableValues.Std());

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Use the suggested helper method to create the context and reduce duplication.
   
   ```suggestion
       // Create a fresh context that is correctly associated with the active 
parser.
       // Using copy() here would leave the context's transient parser field as 
null,
       // causing NullPointerExceptions in Jackson 2.14+ deserializers during 
coercion
       // validations and length checks.
       DefaultDeserializationContext context = 
createDeserializationContext(parser);
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to