Fix JdkObsolete issues with SortedMap
This is a step towards enabling the error level for the JdkObsolete
error prone check.
Use NavigableMap instead of SortedMap.
Bug: Issue 15070
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I711e72e810e9fafbbd584138dec3720aa48086c9
diff --git a/java/com/google/gerrit/httpd/auth/oauth/OAuthWebFilter.java b/java/com/google/gerrit/httpd/auth/oauth/OAuthWebFilter.java
index 8c07637..935762f 100644
--- a/java/com/google/gerrit/httpd/auth/oauth/OAuthWebFilter.java
+++ b/java/com/google/gerrit/httpd/auth/oauth/OAuthWebFilter.java
@@ -31,9 +31,9 @@
import com.google.inject.Singleton;
import java.io.IOException;
import java.util.Map;
+import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.Set;
-import java.util.SortedMap;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -180,7 +180,7 @@
throw new ServletException("OAuth service provider wasn't installed");
}
if (plugins.size() == 1) {
- SortedMap<String, Provider<OAuthServiceProvider>> services =
+ NavigableMap<String, Provider<OAuthServiceProvider>> services =
oauthServiceProviders.byPlugin(Iterables.getOnlyElement(plugins));
if (services.size() == 1) {
ssoProvider = Iterables.getOnlyElement(services.values()).get();
diff --git a/java/com/google/gerrit/httpd/auth/openid/OAuthWebFilterOverOpenID.java b/java/com/google/gerrit/httpd/auth/openid/OAuthWebFilterOverOpenID.java
index e5a2cb9..3d9c819 100644
--- a/java/com/google/gerrit/httpd/auth/openid/OAuthWebFilterOverOpenID.java
+++ b/java/com/google/gerrit/httpd/auth/openid/OAuthWebFilterOverOpenID.java
@@ -21,8 +21,8 @@
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
+import java.util.NavigableMap;
import java.util.NavigableSet;
-import java.util.SortedMap;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -81,7 +81,7 @@
private void pickSSOServiceProvider() {
NavigableSet<String> plugins = oauthServiceProviders.plugins();
if (plugins.size() == 1) {
- SortedMap<String, Provider<OAuthServiceProvider>> services =
+ NavigableMap<String, Provider<OAuthServiceProvider>> services =
oauthServiceProviders.byPlugin(Iterables.getOnlyElement(plugins));
if (services.size() == 1) {
ssoProvider = Iterables.getOnlyElement(services.values()).get();
diff --git a/java/com/google/gerrit/metrics/dropwizard/ListMetrics.java b/java/com/google/gerrit/metrics/dropwizard/ListMetrics.java
index 7e472c9..6b17456 100644
--- a/java/com/google/gerrit/metrics/dropwizard/ListMetrics.java
+++ b/java/com/google/gerrit/metrics/dropwizard/ListMetrics.java
@@ -26,7 +26,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import java.util.SortedMap;
+import java.util.NavigableMap;
import java.util.TreeMap;
import org.kohsuke.args4j.Option;
@@ -55,7 +55,7 @@
throws AuthException, PermissionBackendException {
permissionBackend.currentUser().check(GlobalPermission.VIEW_CACHES);
- SortedMap<String, MetricJson> out = new TreeMap<>();
+ NavigableMap<String, MetricJson> out = new TreeMap<>();
List<String> prefixes = new ArrayList<>(query.size());
for (String q : query) {
if (q.endsWith("/")) {
diff --git a/java/com/google/gerrit/server/group/SystemGroupBackend.java b/java/com/google/gerrit/server/group/SystemGroupBackend.java
index a63feeb..5a9b9e5 100644
--- a/java/com/google/gerrit/server/group/SystemGroupBackend.java
+++ b/java/com/google/gerrit/server/group/SystemGroupBackend.java
@@ -45,9 +45,9 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.NavigableMap;
import java.util.Optional;
import java.util.Set;
-import java.util.SortedMap;
import java.util.TreeMap;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
@@ -89,7 +89,7 @@
}
private final ImmutableSet<String> reservedNames;
- private final SortedMap<String, GroupReference> namesToGroups;
+ private final NavigableMap<String, GroupReference> namesToGroups;
private final ImmutableSet<String> names;
private final ImmutableMap<AccountGroup.UUID, GroupReference> uuids;
private final ImmutableSet<AccountGroup.UUID> externalUserMemberships;
@@ -97,7 +97,7 @@
@Inject
@VisibleForTesting
public SystemGroupBackend(@GerritServerConfig Config cfg) {
- SortedMap<String, GroupReference> n = new TreeMap<>();
+ NavigableMap<String, GroupReference> n = new TreeMap<>();
ImmutableMap.Builder<AccountGroup.UUID, GroupReference> u = ImmutableMap.builder();
ImmutableSet.Builder<String> reservedNamesBuilder = ImmutableSet.builder();
@@ -112,7 +112,7 @@
u.put(ref.getUUID(), ref);
}
reservedNames = reservedNamesBuilder.build();
- namesToGroups = Collections.unmodifiableSortedMap(n);
+ namesToGroups = Collections.unmodifiableNavigableMap(n);
names =
ImmutableSet.copyOf(
namesToGroups.values().stream().map(GroupReference::getName).collect(toSet()));
@@ -172,7 +172,8 @@
@Override
public Collection<GroupReference> suggest(String name, ProjectState project) {
String nameLC = name.toLowerCase(Locale.US);
- SortedMap<String, GroupReference> matches = namesToGroups.tailMap(nameLC);
+ NavigableMap<String, GroupReference> matches =
+ namesToGroups.tailMap(nameLC, /* inclusive= */ true);
if (matches.isEmpty()) {
return new ArrayList<>();
}
diff --git a/java/com/google/gerrit/server/restapi/group/ListGroups.java b/java/com/google/gerrit/server/restapi/group/ListGroups.java
index 854f091..b94e44d 100644
--- a/java/com/google/gerrit/server/restapi/group/ListGroups.java
+++ b/java/com/google/gerrit/server/restapi/group/ListGroups.java
@@ -57,8 +57,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
+import java.util.NavigableMap;
import java.util.Set;
-import java.util.SortedMap;
import java.util.TreeMap;
import java.util.function.Predicate;
import java.util.regex.Pattern;
@@ -235,8 +235,9 @@
}
@Override
- public Response<SortedMap<String, GroupInfo>> apply(TopLevelResource resource) throws Exception {
- SortedMap<String, GroupInfo> output = new TreeMap<>();
+ public Response<NavigableMap<String, GroupInfo>> apply(TopLevelResource resource)
+ throws Exception {
+ NavigableMap<String, GroupInfo> output = new TreeMap<>();
for (GroupInfo info : get()) {
output.put(MoreObjects.firstNonNull(info.name, "Group " + Url.decode(info.id)), info);
info.name = null;
diff --git a/java/com/google/gerrit/server/tools/ToolsCatalog.java b/java/com/google/gerrit/server/tools/ToolsCatalog.java
index 9c1483f..015b8f1 100644
--- a/java/com/google/gerrit/server/tools/ToolsCatalog.java
+++ b/java/com/google/gerrit/server/tools/ToolsCatalog.java
@@ -31,7 +31,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.SortedMap;
+import java.util.NavigableMap;
import java.util.TreeMap;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.util.RawParseUtils;
@@ -46,7 +46,7 @@
public class ToolsCatalog {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
- private final SortedMap<String, Entry> toc;
+ private final NavigableMap<String, Entry> toc;
@Inject
ToolsCatalog() throws IOException {
@@ -73,8 +73,8 @@
return toc.get(name);
}
- private static SortedMap<String, Entry> readToc() throws IOException {
- SortedMap<String, Entry> toc = new TreeMap<>();
+ private static NavigableMap<String, Entry> readToc() throws IOException {
+ NavigableMap<String, Entry> toc = new TreeMap<>();
final BufferedReader br =
new BufferedReader(new InputStreamReader(new ByteArrayInputStream(read("TOC")), UTF_8));
String line;
@@ -108,7 +108,7 @@
}
toc.put(top.getPath(), top);
- return Collections.unmodifiableSortedMap(toc);
+ return Collections.unmodifiableNavigableMap(toc);
}
@Nullable