Skip to content

Commit

Permalink
ProbeInserter should update indexes of local variables in annotations (
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin authored and marchof committed Jun 11, 2019
1 parent 219088d commit 6c62355
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Expand Up @@ -18,8 +18,10 @@
import org.junit.Before;
import org.junit.Test;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.TypeReference;

/**
* Unit tests for {@link ProbeInserter}.
Expand Down Expand Up @@ -182,6 +184,28 @@ public void testVisitLocalVariable() {
expectedVisitor.visitLocalVariable(null, null, null, null, null, 5);
}

@Test
public void should_remap_LocalVariableAnnotation() {
ProbeInserter pi = new ProbeInserter(0, "m", "(I)V", actualVisitor,
arrayStrategy);

final Label start = new Label();
pi.visitLabel(start);
final Label end = new Label();
pi.visitLabel(end);

pi.visitLocalVariableAnnotation(TypeReference.LOCAL_VARIABLE, null,
new Label[] { start }, new Label[] { end }, new int[] { 2 },
"LNonNull;", false);

expectedVisitor.visitLabel(start);
expectedVisitor.visitLabel(end);
// Local variables are shifted by one:
expectedVisitor.visitLocalVariableAnnotation(
TypeReference.LOCAL_VARIABLE, null, new Label[] { start },
new Label[] { end }, new int[] { 3 }, "LNonNull;", false);
}

@Test
public void testVisitMaxs1() {
ProbeInserter pi = new ProbeInserter(0, "m", "(II)V", actualVisitor,
Expand Down
Expand Up @@ -11,10 +11,12 @@
*******************************************************************************/
package org.jacoco.core.internal.instr;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.TypePath;

/**
* Internal utility to add probes into the control flow of a method. The code
Expand Down Expand Up @@ -111,6 +113,18 @@ public final void visitLocalVariable(final String name, final String desc,
mv.visitLocalVariable(name, desc, signature, start, end, map(index));
}

@Override
public AnnotationVisitor visitLocalVariableAnnotation(final int typeRef,
final TypePath typePath, final Label[] start, final Label[] end,
final int[] index, final String descriptor, final boolean visible) {
final int[] newIndex = new int[index.length];
for (int i = 0; i < newIndex.length; i++) {
newIndex[i] = map(index[i]);
}
return mv.visitLocalVariableAnnotation(typeRef, typePath, start, end,
newIndex, descriptor, visible);
}

@Override
public void visitMaxs(final int maxStack, final int maxLocals) {
// Max stack size of the probe code is 3 which can add to the
Expand Down
2 changes: 2 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Expand Up @@ -32,6 +32,8 @@ <h3>Fixed bugs</h3>
<li><code>synthetic</code> constructors that contain values of default arguments
in Kotlin should not be ignored
(GitHub <a href="https://github.com/jacoco/jacoco/issues/888">#888</a>).</li>
<li>Instrumentation should update indexes of local variables in annotations
(GitHub <a href="https://github.com/jacoco/jacoco/issues/894">#894</a>).</li>
</ul>

<h2>Release 0.8.4 (2019/05/08)</h2>
Expand Down

0 comments on commit 6c62355

Please sign in to comment.