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

   ### What changes were proposed in this pull request?
   
   Multiple REST handlers dereference `request` (e.g. `request.getName()`, 
`request.getRoleNames()`, `request.getJobTemplate().name()`) inside `catch 
(Exception e)` blocks. When `request` is `null` (e.g. from an empty or 
malformed POST body), the catch block throws a secondary `NullPointerException` 
that masks the real failure.
   
   This PR replaces all catch-path request dereferences with null-safe 
precomputed local variables across 16 REST handler files:
   
   - Simple `getName()` pattern (11 files): Table, Fileset, Function, Model, 
Schema, Catalog, User, Group, Role, Policy, Tag, Topic
   - `getRoleNames()` pattern: PermissionOperations (4 catch sites)
   - Nested `getJobTemplate().name()`: JobOperations
   - `isInUse()` pattern: MetalakeOperations, CatalogOperations
   - `getNames()` pattern: StatisticOperations
   
   ### Why are the changes needed?
   
   When `request` is null and an exception occurs in the method body, the catch 
block tries to dereference `request.get*()`, throwing a secondary NPE that 
masks the original exception. This makes debugging harder as the real error is 
lost. The fix ensures catch blocks always preserve the primary error through 
existing `ExceptionHandlers`.
   
   Reproducible by sending an empty body to any affected endpoint:
   ```
   POST /api/metalakes/m/catalogs/c/schemas
   Content-Type: application/json
   Accept: application/vnd.gravitino.v1+json
   (empty body)
   ```
   
   Fix: #10172
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. Error handling behavior is preserved — endpoints return the same error 
responses, but the original exception is no longer masked by a secondary NPE.
   
   ### How was this patch tested?
   
   - Added null-request-body regression tests in `TestGroupOperations` and 
`TestPermissionOperations` covering the two main dereference patterns 
(`getName()` and `getRoleNames()`).
   - All existing tests pass: `./gradlew :server:test -PskipITs`


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