justinmclean commented on PR #10187:
URL: https://github.com/apache/gravitino/pull/10187#issuecomment-4000364325
@jerryshao I verified this behavior in the current codebase, and null
request bodies are actually reachable in REST handlers.
TestMetalakeOperations#testCreateMetalakeWithNullRequest sends
Entity.entity(null, MediaType.APPLICATION_JSON_TYPE) and passes, which means
Jersey/Jackson does not universally reject this before resource logic. Without
the guard in createSchema, we hit an NPE path (request.getName()).
So this case is valid.
But to double-check here, a higher-level test confirming the issue.
```
@Test
public void testCreateSchemaWithNullRequestBodyViaHttpServer() throws
Exception {
gravitinoServer.initialize();
gravitinoServer.start();
HttpURLConnection connection =
(HttpURLConnection)
new URL("http://127.0.0.1:" + httpPort +
"/api/metalakes/m/catalogs/c/schemas")
.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept",
"application/vnd.gravitino.v1+json");
connection.setDoOutput(true);
connection.getOutputStream().close();
assertEquals(500, connection.getResponseCode());
}
private String readResponseBody(HttpURLConnection connection) throws
IOException {
InputStream inputStream =
connection.getErrorStream() != null
? connection.getErrorStream()
: connection.getInputStream();
if (inputStream == null) {
return "";
}
try (InputStream stream = inputStream;
ByteArrayOutputStream output = new ByteArrayOutputStream()) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = stream.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
return output.toString(StandardCharsets.UTF_8.name());
}
}
```
The call is basically:
```
POST /api/metalakes/m/catalogs/c/schemas
Content-Type: application/json
Accept: application/vnd.gravitino.v1+json
Body: <empty>
```
As you can see from the test that returns an HTTP status of 500 when it
should return 400 Bad Request with an ErrorResponse with code 1001
(ILLEGAL_ARGUMENTS_CODE) and type "IllegalArgumentException".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]