hobostay opened a new pull request, #10158: URL: https://github.com/apache/gravitino/pull/10158
## What this PR does Fixes #10123 The `createMetalake` REST handler can crash with a `NullPointerException` when the request body is missing or deserializes to null. The issue was that: 1. The handler logs `request.getName()` before validation - if `request` is null, this throws NPE 2. The exception handler also calls `request.getName()` - if `request` is null, this throws another NPE 3. This results in an internal server error instead of a proper client error response ## Changes - **MetalakeOperations.java**: Added explicit null check for request at the start of `createMetalake()` method - **MetalakeOperations.java**: Safely retrieves metalake name in exception handler using ternary operator - **TestMetalakeOperations.java**: Added new test `testCreateMetalakeWithNullRequest()` to verify null request handling ## Behavior - When request is null, the endpoint now returns a proper `BAD_REQUEST` response with clear error message - No NPE is thrown during request processing or exception handling - Error message clearly states "Request body cannot be null" ## Testing Added unit test `testCreateMetalakeWithNullRequest()` that verifies: - Null request returns BAD_REQUEST status code (not INTERNAL_SERVER_ERROR) - Error response has correct error code (ILLEGAL_ARGUMENTS) - Error response has correct type (IllegalArgumentException) - Error message contains "Request body cannot be null" --- Co-Authored-By: Claude Opus 4.6 <[email protected]> -- 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]
