apache/gravitino

[Improvement] Possible NPE in SchemaOperations#createSchema

Open

#10,164 创建于 2026年3月3日

在 GitHub 查看
 (2 评论) (0 反应) (1 负责人)Java (887 fork)auto 404
good first issueimprovement

仓库指标

Star
 (3,058 star)
PR 合并指标
 (PR 指标待抓取)

描述

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));
  }

贡献者指南