World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#8122] fix(core): Fix unable to handle Java error in doAs (#8184)
Mini Yu8c979e9b0644
diff --git a/core/src/main/java/org/apache/gravitino/utils/PrincipalUtils.java b/core/src/main/java/org/apache/gravitino/utils/PrincipalUtils.javaindex ee8b0a0ee5..098ba50486 100644--- a/core/src/main/java/org/apache/gravitino/utils/PrincipalUtils.java+++ b/core/src/main/java/org/apache/gravitino/utils/PrincipalUtils.java@@ -26,9 +26,14 @@ import java.security.PrivilegedExceptionAction;import javax.security.auth.Subject;import org.apache.gravitino.UserPrincipal;import org.apache.gravitino.auth.AuthConstants;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;@SuppressWarnings("removal")public class PrincipalUtils {++ private static final Logger LOG = LoggerFactory.getLogger(PrincipalUtils.class);+private PrincipalUtils() {}public static <T> T doAs(Principal principal, PrivilegedExceptionAction<T> action)@@ -41,6 +46,9 @@ public class PrincipalUtils {Throwable cause = pae.getCause();Throwables.propagateIfPossible(cause, Exception.class);throw new RuntimeException("doAs method occurs an unexpected exception", pae);+ } catch (Error t) {+ LOG.warn("doAs method occurs an unexpected error", t);+ throw new RuntimeException("doAs method occurs an unexpected exception", t);}}diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestFilesetOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestFilesetOperations.javaindex 56665ae914..2878e93ccd 100644--- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestFilesetOperations.java+++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestFilesetOperations.java@@ -373,6 +373,21 @@ public class TestFilesetOperations extends BaseOperationsTest {ErrorResponse errorResp3 = resp3.readEntity(ErrorResponse.class);Assertions.assertEquals(ErrorConstants.INTERNAL_ERROR_CODE, errorResp3.getCode());Assertions.assertEquals(RuntimeException.class.getSimpleName(), errorResp3.getType());++ // Test throw Error+ doThrow(new Error("mock error"))+ .when(dispatcher)+ .createMultipleLocationFileset(any(), any(), any(), any(), any());+ Response resp4 =+ target(filesetPath(metalake, catalog, schema))+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .post(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE));+ Assertions.assertEquals(+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), resp4.getStatus());+ ErrorResponse errorResp4 = resp4.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.INTERNAL_ERROR_CODE, errorResp4.getCode());+ Assertions.assertEquals(RuntimeException.class.getSimpleName(), errorResp4.getType());}@Test