Make reading event sequence files safer

Capture ArrayIndexOutOfBoundsException which is a RuntimeException and
therefore was missed. This exception can be thrown when reading a file
which is concurrently updated. This exception has been seen when the
value file was replaced (a normal occurrence for any updates).
Previously if this exception occurred, then the Gerrit operation causing
the event could fail and the event could be lost; this should no longer
be the case.

Change-Id: Id53f9529ba921d6d7ba6a32be1ece73987f91ec0
diff --git a/src/main/java/com/googlesource/gerrit/plugins/events/fsstore/Fs.java b/src/main/java/com/googlesource/gerrit/plugins/events/fsstore/Fs.java
index 96f7db1..85334bd 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/events/fsstore/Fs.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/events/fsstore/Fs.java
@@ -155,6 +155,16 @@
 
   /** Read the contents of a UTF_8 encoded file as a String */
   public static String readUtf8(Path file) throws IOException {
+    try {
+      return readUtf8Unsafe(file);
+    } catch (ArrayIndexOutOfBoundsException e) {
+      // A concurrent update can cause this, make sure Exception becomes checked.
+      throw new IOException("File modified or deleted during read.", e);
+    }
+  }
+
+  /** Read the contents of a UTF_8 encoded file as a String */
+  protected static String readUtf8Unsafe(Path file) throws IOException {
     StringBuffer buffer = new StringBuffer();
     for (String line : Files.readAllLines(file, StandardCharsets.UTF_8)) {
       buffer.append(line);