Fix GitOverHttpServlet compilation on servlet API 2.5
Inlining the assignment[1] seemed harmless, but the explicit cast is
required since 2.5 uses raw types. This meant the "v" in the lambda was
an Object, which is not valid in a foreach loop.
Restore the explicit cast, and shrink the code down a bit more while
we're at it.
[1] https://gerrit-review.googlesource.com/c/gerrit/+/206110/3..5
Change-Id: I2cb89d9e343d2d163921036110fe29521d7da113
diff --git a/java/com/google/gerrit/httpd/GitOverHttpServlet.java b/java/com/google/gerrit/httpd/GitOverHttpServlet.java
index f4b0a9a..2e1b562 100644
--- a/java/com/google/gerrit/httpd/GitOverHttpServlet.java
+++ b/java/com/google/gerrit/httpd/GitOverHttpServlet.java
@@ -15,7 +15,7 @@
package com.google.gerrit.httpd;
import com.google.common.cache.Cache;
-import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
import com.google.gerrit.common.data.Capable;
@@ -52,6 +52,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -206,19 +207,15 @@
}
private static ListMultimap<String, String> extractParameters(HttpServletRequest request) {
-
- ListMultimap<String, String> multiMap = ArrayListMultimap.create();
- if (request.getQueryString() != null) {
- request
- .getParameterMap()
- .forEach(
- (k, v) -> {
- for (String aV : v) {
- multiMap.put(k, aV);
- }
- });
+ if (request.getQueryString() == null) {
+ return ImmutableListMultimap.of();
}
- return multiMap;
+ // Explicit cast is required to compile under Servlet API 2.5, where the return type is raw Map.
+ @SuppressWarnings("cast")
+ Map<String, String[]> parameterMap = (Map<String, String[]>) request.getParameterMap();
+ ImmutableListMultimap.Builder<String, String> b = ImmutableListMultimap.builder();
+ parameterMap.forEach(b::putAll);
+ return b.build();
}
static class Resolver implements RepositoryResolver<HttpServletRequest> {