Stop using Maps.newTreeMap(Comparator) due to OpenJDK 6 bug

OpenJDK 6 does not allow to properly infer types for
Maps.newTreeMap(Comparator):
  http://bugs.openjdk.java.net/show_bug.cgi?id=100167#c1

Due to this problem, compiling on OpenJDK 6 (e.g.:

  OpenJDK Runtime Environment (IcedTea6 1.11.3) (Gentoo build 1.6.0_24-b24)
  OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

) resulted in the following failure upon 'mvn compile':

  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project gerrit-server: Compilation failure: Compilation failure:
  [ERROR] /home/christian/sources/Wikimedia/gerrit/gerrit-git/gerrit-server/src/main/java/com/google/gerrit/server/change/ReviewerJson.java:[91,35] incompatible types; no instance(s) of type variable(s) K,V exist so that java.util.TreeMap<K,V> conforms to java.util.Map<java.lang.String,java.lang.String>
  [ERROR] found   : <K,V>java.util.TreeMap<K,V>
  [ERROR] required: java.util.Map<java.lang.String,java.lang.String>
  [ERROR] /home/christian/sources/Wikimedia/gerrit/gerrit-git/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java:[357,23] incompatible types; no instance(s) of type variable(s) K,V exist so that java.util.TreeMap<K,V> conforms to java.util.Map<java.lang.String,com.google.gerrit.server.change.ChangeJson.LabelInfo>
  [ERROR] found   : <K,V>java.util.TreeMap<K,V>
  [ERROR] required: java.util.Map<java.lang.String,com.google.gerrit.server.change.ChangeJson.LabelInfo>
  [ERROR] /home/christian/sources/Wikimedia/gerrit/gerrit-git/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java:[475,23] incompatible types; no instance(s) of type variable(s) K,V exist so that java.util.TreeMap<K,V> conforms to java.util.Map<java.lang.String,com.google.gerrit.server.change.ChangeJson.LabelInfo>
  [ERROR] found   : <K,V>java.util.TreeMap<K,V>
  [ERROR] required: java.util.Map<java.lang.String,com.google.gerrit.server.change.ChangeJson.LabelInfo>
  [ERROR] -> [Help 1]

To work around those problems, we now instantiate the TreeMaps
directly. Thereby, we can again compile on OpenJDK 6.

Change-Id: I83e2eff523f432328efcde7b2d3d9b258523450e
This commit is contained in:
Christian Aistleitner
2013-02-27 18:07:44 +01:00
committed by Gerrit Code Review
parent 1a3f9cc139
commit 278aa9a4e6
2 changed files with 10 additions and 4 deletions

View File

@@ -18,7 +18,6 @@ import static com.google.gerrit.reviewdb.client.ApprovalCategoryValue.formatValu
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gerrit.common.data.ApprovalType;
import com.google.gerrit.common.data.ApprovalTypes;
import com.google.gerrit.common.data.Permission;
@@ -39,6 +38,7 @@ import com.google.inject.Provider;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class ReviewerJson {
private final Provider<ReviewDb> db;
@@ -88,7 +88,9 @@ public class ReviewerJson {
CategoryFunction.forCategory(at.getCategory()).run(at, fs);
}
out.approvals = Maps.newTreeMap(LabelOrdering.create(approvalTypes));
// Don't use Maps.newTreeMap(Comparator) due to OpenJDK bug 100167.
out.approvals = new TreeMap<String,String>(LabelOrdering.create(
approvalTypes));
for (PatchSetApproval ca : approvals) {
for (PermissionRange pr : ctl.getLabelRanges()) {
if (!pr.isEmpty()) {