Track #103: Better error message when multiple JaCoCo agents are specified.
diff --git a/org.jacoco.core.test/src/org/jacoco/core/runtime/ModifiedSystemClassRuntimeTest.java b/org.jacoco.core.test/src/org/jacoco/core/runtime/ModifiedSystemClassRuntimeTest.java
index d3057e5..2baaabc 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/runtime/ModifiedSystemClassRuntimeTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/runtime/ModifiedSystemClassRuntimeTest.java
@@ -42,17 +42,9 @@
 				ModifiedSystemClassRuntimeTest.class, "accessField");

 	}

 

-	@Test

-	public void testCreateFor() throws Exception {

-		InstrumentationMock inst = new InstrumentationMock(true);

-		ModifiedSystemClassRuntime.createFor(inst, TARGET_CLASS_NAME);

-		assertTrue(inst.added);

-		assertTrue(inst.removed);

-	}

-

 	@Test(expected = RuntimeException.class)

 	public void testCreateForNegative() throws Exception {

-		InstrumentationMock inst = new InstrumentationMock(false);

+		InstrumentationMock inst = new InstrumentationMock();

 		ModifiedSystemClassRuntime.createFor(inst, TARGET_CLASS_NAME);

 	}

 

@@ -63,35 +55,25 @@
 

 	private static class InstrumentationMock implements Instrumentation {

 

-		private final boolean doTransform;

-

 		boolean added = false;

 

 		boolean removed = false;

 

-		InstrumentationMock(boolean doTransform) {

-			this.doTransform = doTransform;

-		}

-

 		public void addTransformer(ClassFileTransformer transformer) {

 			assertFalse(added);

 			added = true;

-			if (doTransform) {

-				try {

-					// Our class should get instrumented:

-					final byte[] data = TargetLoader

-							.getClassDataAsBytes(ModifiedSystemClassRuntimeTest.class);

-					verifyInstrumentedClass(TARGET_CLASS_NAME, transformer

-							.transform(null, TARGET_CLASS_NAME, null, null,

-									data));

+			try {

+				// Our class should get instrumented:

+				final byte[] data = TargetLoader

+						.getClassDataAsBytes(ModifiedSystemClassRuntimeTest.class);

+				verifyInstrumentedClass(TARGET_CLASS_NAME, transformer

+						.transform(null, TARGET_CLASS_NAME, null, null, data));

 

-					// Other classes will not be instrumented:

-					assertNull(transformer.transform(getClass()

-							.getClassLoader(), "some/other/Class", null, null,

-							new byte[0]));

-				} catch (Exception e) {

-					throw new RuntimeException(e);

-				}

+				// Other classes will not be instrumented:

+				assertNull(transformer.transform(getClass().getClassLoader(),

+						"some/other/Class", null, null, new byte[0]));

+			} catch (Exception e) {

+				throw new RuntimeException(e);

 			}

 		}

 

diff --git a/org.jacoco.core/src/org/jacoco/core/runtime/ModifiedSystemClassRuntime.java b/org.jacoco.core/src/org/jacoco/core/runtime/ModifiedSystemClassRuntime.java
index d7a5cf4..6829ad6 100644
--- a/org.jacoco.core/src/org/jacoco/core/runtime/ModifiedSystemClassRuntime.java
+++ b/org.jacoco.core/src/org/jacoco/core/runtime/ModifiedSystemClassRuntime.java
@@ -122,14 +122,12 @@
 	public static IRuntime createFor(final Instrumentation inst,

 			final String className, final String accessFieldName)

 			throws ClassNotFoundException {

-		final boolean[] instrumented = new boolean[] { false };

 		final ClassFileTransformer transformer = new ClassFileTransformer() {

 			public byte[] transform(final ClassLoader loader,

 					final String name, final Class<?> classBeingRedefined,

 					final ProtectionDomain protectionDomain, final byte[] source)

 					throws IllegalClassFormatException {

 				if (name.equals(className)) {

-					instrumented[0] = true;

 					return instrument(source, accessFieldName);

 				}

 				return null;

@@ -138,9 +136,11 @@
 		inst.addTransformer(transformer);

 		final Class<?> clazz = Class.forName(className.replace('/', '.'));

 		inst.removeTransformer(transformer);

-		if (!instrumented[0]) {

-			final String msg = format("Class %s was not loaded.", className);

-			throw new RuntimeException(msg);

+		try {

+			clazz.getField(accessFieldName);

+		} catch (final NoSuchFieldException e) {

+			throw new RuntimeException(format("Class %s could not be instrumented.",

+					className));

 		}

 		return new ModifiedSystemClassRuntime(clazz, accessFieldName);

 	}

diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html
index c0e8b41..e68137a 100644
--- a/org.jacoco.doc/docroot/doc/changes.html
+++ b/org.jacoco.doc/docroot/doc/changes.html
@@ -18,6 +18,14 @@
 

 <h1>Change History</h1>

 

+<h2>Trunk Build @qualified.bundle.version@ (@build.date@)</h2>

+

+<h3>Fixed Bugs</h3>

+<ul>

+  <li>Better error message when multiple JaCoCo agents are specified. 

+      (Track #103).</li>

+</ul>

+

 <h2>Release 0.4.0 (2010/06/04)</h2>

 

 <h3>New Features</h3>