github-actions[bot] commented on code in PR #61685:
URL: https://github.com/apache/doris/pull/61685#discussion_r2984204361


##########
fe/fe-core/src/main/java/org/apache/doris/datasource/es/EsExternalTable.java:
##########
@@ -87,25 +125,68 @@ public Map<String, String> getColumn2type() {
         return schemaCacheValue.map(value -> ((EsSchemaCacheValue) 
value).getColumn2typeMap()).orElse(null);
     }
 
-    private EsTable toEsTable() {
-        List<Column> schema = getFullSchema();
-        Map<String, String> column2typeMap = getColumn2type();

Review Comment:
   **Potential null-safety issue:** `getColumn2type()` returns `null` via 
`.orElse(null)` when `getSchemaCacheValue()` returns `Optional.empty()`. This 
value is then assigned to `this.column2typeMap` in `initEsState()` (line 171 in 
the new code), overwriting the safe field default of `new HashMap<>()`.
   
   Downstream, in `EsScanNode.java:349`, `table.getColumn2typeMap()` passes 
this field to `QueryBuilders.toEsDsl()`, which at `QueryBuilders.java:298` 
calls `column2typeMap.get(column)` — this would NPE if the map is null.
   
   The Lombok `@Getter` for `column2typeMap` does **not** call 
`makeSureInitialized()`, so while in practice the caller (`EsScanNode`) calls 
`table.fieldsContext()` first (which triggers initialization), the null can 
still be stored if `getSchemaCacheValue()` returns empty (e.g., catalog was 
invalidated).
   
   Note: the existing `ExternalTable.getFullSchema()` also uses 
`.orElse(null)`, so this is a pre-existing pattern. However, unlike 
`getFullSchema()`, here the null overwrites a field's safe default.
   
   Suggested fix:
   ```java
   return schemaCacheValue.map(value -> ((EsSchemaCacheValue) 
value).getColumn2typeMap()).orElse(new HashMap<>());
   ```
   Or alternatively, guard the assignment in `initEsState()`:
   ```java
   Map<String, String> typeMap = getColumn2type();
   this.column2typeMap = typeMap != null ? typeMap : new HashMap<>();
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to