Skip to content

Commit

Permalink
Fix NPE in StringSwitchEcjFilter (#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin authored and marchof committed Sep 22, 2019
1 parent 19ef126 commit 18f571a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Expand Up @@ -155,4 +155,22 @@ public void should_filter_when_default_is_first() {
assertIgnored(new Range(switchNode.getNext(), 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.visitVarInsn(Opcodes.ASTORE, 2);
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 @@ -70,6 +70,10 @@ public void match(final AbstractInsnNode start,
final Set<AbstractInsnNode> replacements = new HashSet<AbstractInsnNode>();
replacements.add(skipNonOpcodes(defaultLabel));

if (hashCodes == 0) {
return;
}

for (int i = 0; i < hashCodes; i++) {
while (true) {
nextIsVar(Opcodes.ALOAD, "s");
Expand Down
3 changes: 2 additions & 1 deletion org.jacoco.doc/docroot/doc/changes.html
Expand Up @@ -48,7 +48,8 @@ <h3>Fixed bugs</h3>
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>
(GitHub <a href="https://github.com/jacoco/jacoco/issues/942">#942</a>,
<a href="https://github.com/jacoco/jacoco/issues/944">#944</a>).</li>
</ul>

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

0 comments on commit 18f571a

Please sign in to comment.