GitHub #397: Improve EOF handling for exec files.

A EOFException should be reported for truncated exec files.
diff --git a/org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java b/org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java
index d5db8ec..cbf5290 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java
@@ -19,6 +19,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Arrays;
@@ -87,17 +88,17 @@
 
 	@Test
 	public void testCustomBlocks() throws IOException {
-		buffer.write(-22);
-		buffer.write(-33);
+		buffer.write(0x55);
+		buffer.write(0x66);
 		final ExecutionDataReader reader = new ExecutionDataReader(
 				new ByteArrayInputStream(buffer.toByteArray())) {
 
 			@Override
 			protected boolean readBlock(byte blocktype) throws IOException {
 				switch (blocktype) {
-				case -22:
+				case 0x55:
 					return true;
-				case -33:
+				case 0x66:
 					return false;
 				}
 				return super.readBlock(blocktype);
@@ -161,9 +162,19 @@
 		createReader().read();
 	}
 
+	@Test(expected = EOFException.class)
+	public void testTruncatedFile() throws IOException {
+		writer.visitClassExecution(new ExecutionData(Long.MIN_VALUE, "Sample",
+				createData(8)));
+		final byte[] content = buffer.toByteArray();
+		buffer.reset();
+		buffer.write(content, 0, content.length - 1);
+		createReaderWithVisitors().read();
+	}
+
 	@Test
 	public void testEmptyFile() throws IOException {
-		buffer = new ByteArrayOutputStream();
+		buffer.reset();
 		createReader().read();
 	}
 
diff --git a/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataReader.java b/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataReader.java
index d67c080..c2be619 100644
--- a/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataReader.java
+++ b/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataReader.java
@@ -13,7 +13,6 @@
 
 import static java.lang.String.format;
 
-import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -79,19 +78,19 @@
 	 */
 	public boolean read() throws IOException,
 			IncompatibleExecDataVersionException {
-		try {
-			byte type;
-			do {
-				type = in.readByte();
-				if (firstBlock && type != ExecutionDataWriter.BLOCK_HEADER) {
-					throw new IOException("Invalid execution data file.");
-				}
-				firstBlock = false;
-			} while (readBlock(type));
-			return true;
-		} catch (final EOFException e) {
-			return false;
-		}
+		byte type;
+		do {
+			int i = in.read();
+			if (i == -1) {
+				return false; // EOF
+			}
+			type = (byte) i;
+			if (firstBlock && type != ExecutionDataWriter.BLOCK_HEADER) {
+				throw new IOException("Invalid execution data file.");
+			}
+			firstBlock = false;
+		} while (readBlock(type));
+		return true;
 	}
 
 	/**
diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html
index ef82fde..1aaa431 100644
--- a/org.jacoco.doc/docroot/doc/changes.html
+++ b/org.jacoco.doc/docroot/doc/changes.html
@@ -20,6 +20,12 @@
 
 <h2>Snapshot Build @qualified.bundle.version@ (@build.date@)</h2>
 
+<h3>Fixed Bugs</h3>
+<ul>
+  <li>Don't suppress EOF errors in case of truncated execution data files
+      (GitHub <a href="https://github.com/jacoco/jacoco/issues/397">#397</a>).</li>
+</ul>
+
 <h3>Non-functional Changes</h3>
 <ul>
   <li>Empty probe arrays are not written to execution data files any more. This