gemini-code-assist[bot] commented on code in PR #38525:
URL: https://github.com/apache/beam/pull/38525#discussion_r3258223025
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java:
##########
@@ -1801,11 +1801,21 @@ static Object deserializeNode(JsonNode node, Method
method) throws IOException {
return null;
}
- JsonParser parser = new TreeTraversingParser(node, MAPPER);
- parser.nextToken();
-
+ JavaType javaType = MAPPER.constructType(method.getGenericReturnType());
JsonDeserializer<Object> jsonDeserializer =
getDeserializerForMethod(method);
- return jsonDeserializer.deserialize(parser,
DESERIALIZATION_CONTEXT.copy());
+ if (jsonDeserializer == null) {
+ return MAPPER.treeToValue(node, javaType);
+ }
+
+ try {
+ JsonParser parser = new TreeTraversingParser(node, MAPPER);
+ parser.nextToken();
+ return jsonDeserializer.deserialize(parser,
DESERIALIZATION_CONTEXT.copy());
+ } catch (NullPointerException e) {
+ // Jackson 2.18+ can yield a non-null contextual JsonDeserializer that
still NPEs for some
+ // pipeline option shapes during display-data serialization (Flink
ValidatesRunner Kafka).
+ return MAPPER.treeToValue(node, javaType);
+ }
Review Comment:

The `javaType` is only used in the fallback paths (when `jsonDeserializer`
is null or when an NPE occurs). Moving its construction into those specific
blocks avoids unnecessary overhead in the common successful path where a
deserializer is available and functional.
```java
JsonDeserializer<Object> jsonDeserializer =
getDeserializerForMethod(method);
if (jsonDeserializer == null) {
JavaType javaType =
MAPPER.constructType(method.getGenericReturnType());
return MAPPER.treeToValue(node, javaType);
}
try {
JsonParser parser = new TreeTraversingParser(node, MAPPER);
parser.nextToken();
return jsonDeserializer.deserialize(parser,
DESERIALIZATION_CONTEXT.copy());
} catch (NullPointerException e) {
// Jackson 2.18+ can yield a non-null contextual JsonDeserializer that
still NPEs for some
// pipeline option shapes during display-data serialization (Flink
ValidatesRunner Kafka).
JavaType javaType =
MAPPER.constructType(method.getGenericReturnType());
return MAPPER.treeToValue(node, javaType);
}
```
--
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]