Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitHub #319: Improved error message for incompatible exec data files.
In case of incompatible execution data formats read from another JaCoCo version ExecutionDataReader.read() now throws a IncompatibleExecDataVersionException with a better error message.
- Loading branch information
Showing
5 changed files
with
129 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
org.jacoco.core.test/src/org/jacoco/core/data/IncompatibleExecDataVersionExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2015 Mountainminds GmbH & Co. KG and Contributors | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Marc R. Hoffmann - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
package org.jacoco.core.data; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for {@link IncompatibleExecDataVersionExceptionTest}. | ||
*/ | ||
public class IncompatibleExecDataVersionExceptionTest { | ||
|
||
private IncompatibleExecDataVersionException exception; | ||
|
||
@Before | ||
public void setup() { | ||
exception = new IncompatibleExecDataVersionException(0x1234); | ||
} | ||
|
||
@Test | ||
public void testGetMessage() { | ||
String expected = "Cannot read execution data version 0x1234. " | ||
+ "This version of JaCoCo uses execution data version 0x" | ||
+ Integer.toHexString(ExecutionDataWriter.FORMAT_VERSION) + "."; | ||
assertEquals(expected, exception.getMessage()); | ||
} | ||
|
||
@Test | ||
public void testGetActualVersion() { | ||
assertEquals(0x1234, exception.getActualVersion()); | ||
} | ||
|
||
@Test | ||
public void testGetExpectedVersion() { | ||
assertEquals(ExecutionDataWriter.FORMAT_VERSION, | ||
exception.getExpectedVersion()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
org.jacoco.core/src/org/jacoco/core/data/IncompatibleExecDataVersionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2015 Mountainminds GmbH & Co. KG and Contributors | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Marc R. Hoffmann, somechris - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
package org.jacoco.core.data; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Signals that execution data in an incompatible version was tried to read. | ||
*/ | ||
public class IncompatibleExecDataVersionException extends IOException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private final int actualVersion; | ||
|
||
/** | ||
* Creates a new exception to flag version mismatches in execution data. | ||
* | ||
* @param actualVersion | ||
* version found in the exec data | ||
*/ | ||
public IncompatibleExecDataVersionException(final int actualVersion) { | ||
super(String.format("Cannot read execution data version 0x%x. " | ||
+ "This version of JaCoCo uses execution data version 0x%x.", | ||
Integer.valueOf(actualVersion), | ||
Integer.valueOf(ExecutionDataWriter.FORMAT_VERSION))); | ||
this.actualVersion = actualVersion; | ||
} | ||
|
||
/** | ||
* Gets the version expected in the execution data which can be read by this | ||
* version of JaCoCo. | ||
* | ||
* @return expected version in execution data | ||
*/ | ||
public int getExpectedVersion() { | ||
return ExecutionDataWriter.FORMAT_VERSION; | ||
} | ||
|
||
/** | ||
* Gets the actual version found in the execution data. | ||
* | ||
* @return actual version in execution data | ||
*/ | ||
public int getActualVersion() { | ||
return actualVersion; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters