robolectric/robolectric — pull request #1234 by rsauciuc (2014-08-18 17:38:56+00:00)
Title: Fix bytecode instrumentation to work on pre-instrumented classes.

Currently, AsmInstrumentingClassLoader wipes out everything in a constructor leading to the invokespecial for "". If the class has already been instrumented, for example for Emma or Jacoco offline code coverage, then part of this instrumentation is destroyed, failing verification at load time due to incorrect bytecode trying to access local variables no longer defined.

Ideally, instrumented classes should not overlap with classes to shadow, but this is not easily enforced. Jacoco is used to instrument everything following a certain package pattern, at the build system level, while shadows can be selected programatically. This bug prevents us from having a working coverage setup.

I'm not sure about the best way to test this change. For now, I created a jar based on the samples in org/robolectric/bytecode/testing, applying Jacoco offline instrumentation. This is enough to illustrate the bug we're facing, but maybe there's an easier setup.