shaojunying opened a new pull request, #10183:
URL: https://github.com/apache/gravitino/pull/10183

   ### What changes were proposed in this pull request?
   
   Add null-safe access for `request` objects in `catch` blocks across 16 REST 
handler files. Each unsafe `request.get*()` call in a catch block is replaced 
with a ternary null check, e.g.:
   
   ```java
   // Before (unsafe):
   request.getName()
   
   // After (safe):
   request != null ? request.getName() : ""
   ```
   
   ### Why are the changes needed?
   
   When `request` is `null` (e.g., due to deserialization failure) and an 
exception occurs inside the `try` block, the `catch` block attempts to 
dereference `request` to build an error message. This throws a secondary 
`NullPointerException` that **masks the original exception**, making debugging 
significantly harder.
   
   The existing fix in `MetalakeOperations.createMetalake` (line 142) already 
demonstrates the correct pattern:
   ```java
   String metalakeName = request != null ? request.getName() : "";
   ```
   
   This PR applies the same pattern consistently across all remaining REST 
handlers.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No API changes. Error responses now correctly reflect the original exception 
instead of being masked by a secondary NPE in the catch block.
   
   ### How was this patch tested?
   
   Manual review of all 16 affected files. The changes are purely defensive — 
they only affect the error path behavior when `request` is null, preserving all 
existing normal-path behavior.
   
   Affected handlers (23 catch-block sites across 16 files):
   
   | File | Method(s) |
   |------|-----------|
   | `CatalogOperations` | `createCatalog`, `testConnection`, `setCatalog` |
   | `SchemaOperations` | `createSchema` |
   | `TableOperations` | `createTable` |
   | `FilesetOperations` | `createFileset` |
   | `FunctionOperations` | `registerFunction` |
   | `ModelOperations` | `registerModel` |
   | `TopicOperations` | `createTopic` |
   | `TagOperations` | `createTag` |
   | `PolicyOperations` | `createPolicy` |
   | `RoleOperations` | `createRole` |
   | `GroupOperations` | `addGroup` |
   | `UserOperations` | `addUser` |
   | `PermissionOperations` | `grantRolesToUser`, `grantRolesToGroup`, 
`revokeRolesFromUser`, `revokeRolesFromGroup` |
   | `JobOperations` | `registerJobTemplate` |
   | `StatisticOperations` | `updateStatistics`, `dropStatistics`, 
`updatePartitionStatistics`, `dropPartitionStatistics` |
   | `MetalakeOperations` | `setMetalake` |
   
   Closes #10172


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