From 4ed52cabeedc5ed38eb7cbc5c90c1b58b1c92647 Mon Sep 17 00:00:00 2001 From: Costin Chiulan <40757474+costichiulan@users.noreply.github.com> Date: Wed, 25 Sep 2024 23:59:56 +0300 Subject: [PATCH] [Fix] Fix parsing issue in ErrorDetail (#328) ## Issue Description Exceptions are not deserialized correctly, the message field contains the response JSON and the string 'Cannot construct instance of com.databricks.sdk.core.error.ErrorDetail, problem: Cannot invoke "Object.getClass()" because "m" is null' ## Changes In ErrorDetails class, i added a null check before the unmodifiableMap is created. ## Tests Created an unit test in ApiErrorBodyDeserializationSuite.java Signed-off-by: Costin Chiulan --- .../com/databricks/sdk/core/error/ErrorDetail.java | 2 +- .../core/error/ApiErrorBodyDeserializationSuite.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/error/ErrorDetail.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/error/ErrorDetail.java index 6b71ccc28..ae6ffb1ec 100644 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/error/ErrorDetail.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/error/ErrorDetail.java @@ -26,7 +26,7 @@ public ErrorDetail( this.type = type; this.reason = reason; this.domain = domain; - this.metadata = Collections.unmodifiableMap(metadata); + this.metadata = metadata != null ? Collections.unmodifiableMap(metadata) : null; } public String getType() { diff --git a/databricks-sdk-java/src/test/java/com/databricks/sdk/core/error/ApiErrorBodyDeserializationSuite.java b/databricks-sdk-java/src/test/java/com/databricks/sdk/core/error/ApiErrorBodyDeserializationSuite.java index ce46d658e..83dae2679 100644 --- a/databricks-sdk-java/src/test/java/com/databricks/sdk/core/error/ApiErrorBodyDeserializationSuite.java +++ b/databricks-sdk-java/src/test/java/com/databricks/sdk/core/error/ApiErrorBodyDeserializationSuite.java @@ -51,4 +51,15 @@ void handleUnexpectedFieldsInErrorResponse() throws JsonProcessingException { assertEquals(error.getErrorCode(), "theerrorcode"); assertEquals(error.getMessage(), "themessage"); } + + @Test + void handleNullMetadataFieldInErrorResponse() throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + String rawResponse = + "{\"error_code\":\"METASTORE_DOES_NOT_EXIST\",\"message\":\"No metastore assigned for the current workspace.\",\"details\":[{\"@type\":\"type.googleapis.com/google.rpc.RequestInfo\",\"request_id\":\"1888e822-f1b5-4996-85eb-0d2b5cc402e6\",\"serving_data\":\"\"}]}"; + ApiErrorBody error = mapper.readValue(rawResponse, ApiErrorBody.class); + + assertEquals(error.getErrorCode(), "METASTORE_DOES_NOT_EXIST"); + assertEquals(error.getMessage(), "No metastore assigned for the current workspace."); + } }