Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in KotlinWhenStringFilter #942

Merged
merged 4 commits into from Sep 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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