Merge "RestApiServlet: Handle exceptions during RequestInfo creation properly"
diff --git a/java/com/google/gerrit/httpd/restapi/RestApiServlet.java b/java/com/google/gerrit/httpd/restapi/RestApiServlet.java
index 6e00d81..89ebdc1 100644
--- a/java/com/google/gerrit/httpd/restapi/RestApiServlet.java
+++ b/java/com/google/gerrit/httpd/restapi/RestApiServlet.java
@@ -328,10 +328,10 @@
     try (TraceContext traceContext = enableTracing(req, res)) {
       List<IdString> path = splitPath(req);
 
-      RequestInfo requestInfo = createRequestInfo(traceContext, requestUri(req), path);
-      globals.requestListeners.runEach(l -> l.onRequest(requestInfo));
-
       try (PerThreadCache ignored = PerThreadCache.create()) {
+        RequestInfo requestInfo = createRequestInfo(traceContext, requestUri(req), path);
+        globals.requestListeners.runEach(l -> l.onRequest(requestInfo));
+
         // It's important that the PerformanceLogContext is closed before the response is sent to
         // the client. Only this way it is ensured that the invocation of the PerformanceLogger
         // plugins happens before the client sees the response. This is needed for being able to