This is an automated email from the ASF dual-hosted git repository.
yuqi1129 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new dbb9ea3193 [#13234] fix(api): put NoSuchEntityException into the
NotFoundException hierarchy (#13235)
dbb9ea3193 is described below
commit dbb9ea319302ea3ebed373ba18d8b73f4b4682d8
Author: YangJie <[email protected]>
AuthorDate: Fri Sep 18 11:23:27 2026 -0400
[#13234] fix(api): put NoSuchEntityException into the NotFoundException
hierarchy (#13235)
### What changes were proposed in this pull request?
`NoSuchEntityException` is re-parented from `RuntimeException` to
`NotFoundException`. Message formatting is unchanged (it delegates to
the existing `@FormatMethod` chain).
### Why are the changes needed?
Extending `RuntimeException` directly put it outside the
`GravitinoRuntimeException`/`NotFoundException` hierarchy its siblings
use, so `catch (NotFoundException)`/`catch (GravitinoRuntimeException)`
missed it and a raw escape mapped to HTTP 500 instead of 404.
Fix: #13234
### Does this PR introduce _any_ user-facing change?
Yes. A `NoSuchEntityException` that escapes to the REST layer now maps
to HTTP 404 instead of 500, like every sibling `NoSuch*` exception. All
in-repo call sites catch it explicitly and are unaffected; message
formatting is unchanged.
### How was this patch tested?
Added `TestExceptions`, which pins that `NoSuchEntityException` is a
`NotFoundException` and is caught by `catch (NotFoundException)`/`catch
(GravitinoRuntimeException)`; it fails on the pre-fix tree and passes
after the fix.
---
.../exceptions/NoSuchEntityException.java | 12 ++++--
.../gravitino/exceptions/TestExceptions.java | 46 ++++++++++++++++++++++
2 files changed, 54 insertions(+), 4 deletions(-)
diff --git
a/api/src/main/java/org/apache/gravitino/exceptions/NoSuchEntityException.java
b/api/src/main/java/org/apache/gravitino/exceptions/NoSuchEntityException.java
index 01fe27a950..8fdbecf3e6 100644
---
a/api/src/main/java/org/apache/gravitino/exceptions/NoSuchEntityException.java
+++
b/api/src/main/java/org/apache/gravitino/exceptions/NoSuchEntityException.java
@@ -21,8 +21,12 @@ package org.apache.gravitino.exceptions;
import com.google.errorprone.annotations.FormatMethod;
import com.google.errorprone.annotations.FormatString;
-/** This exception is thrown when an entity is not found. */
-public class NoSuchEntityException extends RuntimeException {
+/**
+ * This exception is thrown when an entity is not found. It belongs to the
{@link NotFoundException}
+ * hierarchy so callers catching Gravitino runtime or not-found exceptions see
it, like every other
+ * NoSuch* exception.
+ */
+public class NoSuchEntityException extends NotFoundException {
/** The no such entity message for the exception. */
public static final String NO_SUCH_ENTITY_MESSAGE = "No such %s entity: %s";
@@ -34,7 +38,7 @@ public class NoSuchEntityException extends RuntimeException {
*/
@FormatMethod
public NoSuchEntityException(@FormatString String message, Object... args) {
- super(String.format(message, args));
+ super(message, args);
}
/**
@@ -46,6 +50,6 @@ public class NoSuchEntityException extends RuntimeException {
*/
@FormatMethod
public NoSuchEntityException(Throwable cause, @FormatString String message,
Object... args) {
- super(String.format(message, args), cause);
+ super(cause, message, args);
}
}
diff --git
a/api/src/test/java/org/apache/gravitino/exceptions/TestExceptions.java
b/api/src/test/java/org/apache/gravitino/exceptions/TestExceptions.java
new file mode 100644
index 0000000000..7ca970d067
--- /dev/null
+++ b/api/src/test/java/org/apache/gravitino/exceptions/TestExceptions.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.exceptions;
+
+import static
org.apache.gravitino.exceptions.NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestExceptions {
+
+ @Test
+ public void testNoSuchEntityExceptionIsInGravitinoHierarchy() {
+ // Before the fix, NoSuchEntityException extended RuntimeException
directly, outside the
+ // NotFoundException hierarchy every sibling NoSuch* exception uses, so a
raw escape mapped to
+ // HTTP 500 instead of 404. Locals are typed Object so the instanceof
checks below are evaluated
+ // at runtime against the actual hierarchy (error-prone's BadInstanceof
rejects a tautological
+ // check on a statically-known subtype).
+ Object noCause = new NoSuchEntityException(NO_SUCH_ENTITY_MESSAGE,
"table", "a.b.c");
+ Object withCause =
+ new NoSuchEntityException(
+ new IllegalStateException("cause"), NO_SUCH_ENTITY_MESSAGE,
"table", "a.b.c");
+ // NotFoundException is the parent that drives the 404 mapping; pin it
directly rather than only
+ // the broader GravitinoRuntimeException.
+ Assertions.assertTrue(noCause instanceof NotFoundException);
+ Assertions.assertTrue(withCause instanceof NotFoundException);
+ Assertions.assertTrue(noCause instanceof GravitinoRuntimeException);
+ Assertions.assertTrue(withCause instanceof GravitinoRuntimeException);
+ }
+}