apache / apache/gravitino

[Improvement] Possible NPE in SchemaOperations#createSchema

Open
#10,164 2 comments 0 reactions 1 assignee Claimed by @rameshreddy-adutla View on GitHub
good first issue improvement
Dominant language
Java
Stars
3.2k
Forks
935
Avg merge
1d 15h
Merged PRs (30d)
315

Description

### What would you like to be improved?

SchemaOperations#createSchema logs request.getName() before entering its try/catch.
If request is null (for example, empty/missing POST body), this causes an immediate NullPointerException outside the error-handling path. Result: inconsistent 500 behavior.

### How should we improve?

Move all request field access behind a null-safe check inside the try path, and fail fast with a controlled validation error when request == null (for example, treat as bad request).
Also, make the catch path null-safe (don’t call request.getName() unless request is non-null).
Add/keep a unit test for null request input to ensure the endpoint never throws uncaught exceptions.

Here's a unit test to help:
```
@Test
public void testCreateSchemaWithNullRequestShouldNotThrow() {
SchemaOperations operations = new SchemaOperations(dispatcher);
Assertions.assertDoesNotThrow(() -> operations.createSchema(metalake, catalog, null));
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.