Fix bytecode instrumentation to work on pre-instrumented classes.

Currently, AsmInstrumentingClassLoader wipes out everything in a constructor leading to the invokespecial for "<init>". 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.
Done.


On Mon, Aug 18, 2014 at 10:40 AM, Jake Wharton <notifications@github.com>
wrote:

> In src/main/java/org/robolectric/bytecode/AsmInstrumentingClassLoader.java:
>
> > @@ -9,17 +9,7 @@
> >  import org.objectweb.asm.Type;
> >  import org.objectweb.asm.commons.GeneratorAdapter;
> >  import org.objectweb.asm.commons.Method;
> > -import org.objectweb.asm.tree.AbstractInsnNode;
> > -import org.objectweb.asm.tree.AnnotationNode;
> > -import org.objectweb.asm.tree.ClassNode;
> > -import org.objectweb.asm.tree.FieldInsnNode;
> > -import org.objectweb.asm.tree.FieldNode;
> > -import org.objectweb.asm.tree.InsnList;
> > -import org.objectweb.asm.tree.InsnNode;
> > -import org.objectweb.asm.tree.LdcInsnNode;
> > -import org.objectweb.asm.tree.MethodInsnNode;
> > -import org.objectweb.asm.tree.MethodNode;
> > -import org.objectweb.asm.tree.TypeInsnNode;
> > +import org.objectweb.asm.tree.*;
>
> Revert
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/robolectric/robolectric/pull/1234/files#r16369010>.
>