Make year, month, day, hour extraction more resilient

Do not assume year, month, day, hour is always parsable to an integer.
Also, remove dangerous broad implicit conversion from string to integer.

Bug: Issue 10904
Change-Id: I85c7532b218861dba8202088366e0e7c1d155d7d
diff --git a/src/main/scala/com/googlesource/gerrit/plugins/analytics/Contributors.scala b/src/main/scala/com/googlesource/gerrit/plugins/analytics/Contributors.scala
index e57cd1d..f634725 100644
--- a/src/main/scala/com/googlesource/gerrit/plugins/analytics/Contributors.scala
+++ b/src/main/scala/com/googlesource/gerrit/plugins/analytics/Contributors.scala
@@ -24,6 +24,7 @@
 import com.googlesource.gerrit.plugins.analytics.common._
 import org.kohsuke.args4j.{Option => ArgOption}
 
+import scala.util.Try
 
 @CommandMetaData(name = "contributors", description = "Extracts the list of contributors to a project")
 class ContributorsCommand @Inject()(val executor: ContributorsService,
@@ -178,7 +179,7 @@
   def apply(statisticsHandler: Statistics)(uca: AggregatedUserCommitActivity)
   : Iterable[UserActivitySummary] = {
 
-    implicit def stringToIntOrNull(x: String): Integer = if (x.isEmpty) null else new Integer(x)
+    def stringToIntOrNull(x: String): Integer = Try(new Integer(x)).getOrElse(null)
 
     uca.key.split("/", AggregationStrategy.MAX_MAPPING_TOKENS) match {
       case Array(email, year, month, day, hour, branch) =>
@@ -187,7 +188,8 @@
             Option(branch).filter(_.nonEmpty).map(b => Array(b)).getOrElse(Array.empty)
 
           UserActivitySummary(
-            year, month, day, hour, uca.getName, email, stat.commits.size,
+            stringToIntOrNull(year), stringToIntOrNull(month), stringToIntOrNull(day), stringToIntOrNull(hour),
+            uca.getName, email, stat.commits.size,
             stat.numFiles, stat.numDistinctFiles, stat.addedLines, stat.deletedLines,
             stat.commits.toArray, maybeBranches, stat.issues.map(_.code)
               .toArray, stat.issues.map(_.link).toArray, uca.getLatest, stat