Skip to content

Commit

Permalink
Fix NPE in KotlinWhenStringFilter (#942)
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin authored and marchof committed Sep 22, 2019
1 parent d0a73ed commit 19ef126
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Expand Up @@ -105,4 +105,21 @@ public void should_filter() {
assertIgnored(new Range(expectedFromInclusive, expectedToInclusive));
}

@Test
public void should_not_filter_empty_lookup_switch() {
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0,
"name", "(Ljava/lang/String;)V", null, null);
m.visitVarInsn(Opcodes.ALOAD, 1);
m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode",
"()I", false);
final Label defaultCase = new Label();
m.visitLookupSwitchInsn(defaultCase, null, new Label[] {});
m.visitLabel(defaultCase);
m.visitInsn(Opcodes.RETURN);

filter.filter(m, context, output);

assertIgnored();
}

}
Expand Up @@ -67,6 +67,10 @@ public void match(final AbstractInsnNode start,
hashCodes = tableSwitch.labels.size();
}

if (hashCodes == 0) {
return;
}

final Set<AbstractInsnNode> replacements = new HashSet<AbstractInsnNode>();
replacements.add(skipNonOpcodes(defaultLabel));

Expand Down
2 changes: 2 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Expand Up @@ -47,6 +47,8 @@ <h3>Fixed bugs</h3>
<li>To avoid failures with invalid class files report generation now checks
that source references are actually files
(GitHub <a href="https://github.com/jacoco/jacoco/issues/941">#941</a>).</li>
<li><code>NullPointerException</code> during filtering
(GitHub <a href="https://github.com/jacoco/jacoco/issues/942">#942</a>).</li>
</ul>

<h3>Non-functional Changes</h3>
Expand Down

0 comments on commit 19ef126

Please sign in to comment.