Skip to content

Commit 766763d

Browse files
marchofGodin
authored andcommitted
Improve error message displayed when processing instrumented classes (bazel-contrib#703)
1 parent 0bcd964 commit 766763d

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

org.jacoco.core.test/src/org/jacoco/core/internal/instr/InstrSupportTest.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
import org.jacoco.core.internal.BytecodeVersion;
1919
import org.junit.Before;
20+
import org.junit.Rule;
2021
import org.junit.Test;
22+
import org.junit.rules.ExpectedException;
2123
import org.objectweb.asm.Opcodes;
2224
import org.objectweb.asm.util.Printer;
2325
import org.objectweb.asm.util.Textifier;
@@ -31,6 +33,9 @@ public class InstrSupportTest {
3133
private Printer printer;
3234
private TraceMethodVisitor trace;
3335

36+
@Rule
37+
public ExpectedException exception = ExpectedException.none();
38+
3439
@Before
3540
public void setup() {
3641
printer = new Textifier();
@@ -56,17 +61,25 @@ public void needFrames_should_return_true_for_versions_greater_than_or_equal_to_
5661
}
5762

5863
@Test
59-
public void testAssertNotIntrumentedPositive() {
64+
public void assertNotIntrumented_should_accept_non_jacoco_memebers() {
6065
InstrSupport.assertNotInstrumented("run", "Foo");
6166
}
6267

63-
@Test(expected = IllegalStateException.class)
64-
public void testAssertNotIntrumentedField() {
68+
@Test
69+
public void assertNotIntrumented_should_throw_exception_when_jacoco_data_field_is_present() {
70+
exception.expect(IllegalStateException.class);
71+
exception.expectMessage(
72+
"Cannot process instrumented class Foo. Please supply original non-instrumented classes.");
73+
6574
InstrSupport.assertNotInstrumented("$jacocoData", "Foo");
6675
}
6776

68-
@Test(expected = IllegalStateException.class)
69-
public void testAssertNotIntrumentedMethod() {
77+
@Test
78+
public void assertNotIntrumented_should_throw_exception_when_jacoco_init_method_is_present() {
79+
exception.expect(IllegalStateException.class);
80+
exception.expectMessage(
81+
"Cannot process instrumented class Foo. Please supply original non-instrumented classes.");
82+
7083
InstrSupport.assertNotInstrumented("$jacocoInit", "Foo");
7184
}
7285

org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ public static boolean needsFrames(final int version) {
185185
public static void assertNotInstrumented(final String member,
186186
final String owner) throws IllegalStateException {
187187
if (member.equals(DATAFIELD_NAME) || member.equals(INITMETHOD_NAME)) {
188-
throw new IllegalStateException(
189-
format("Class %s is already instrumented.", owner));
188+
throw new IllegalStateException(format(
189+
"Cannot process instrumented class %s. Please supply original non-instrumented classes.",
190+
owner));
190191
}
191192
}
192193

org.jacoco.doc/docroot/doc/changes.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ <h3>Fixed Bugs</h3>
3838
(GitHub <a href="https://github.com/jacoco/jacoco/issues/672">#672</a>).</li>
3939
</ul>
4040

41+
<h3>Non-functional Changes</h3>
42+
<ul>
43+
<li>Improved error message when already instrumented classes are used for
44+
instrumentation or analysis
45+
(GitHub <a href="https://github.com/jacoco/jacoco/issues/703">#703</a>).</li>
46+
</ul>
47+
4148
<h2>Release 0.8.1 (2018/03/21)</h2>
4249

4350
<h3>New Features</h3>

0 commit comments

Comments
 (0)