Skip to content

Commit 19ef126

Browse files
Godinmarchof
authored andcommitted
Fix NPE in KotlinWhenStringFilter (bazel-contrib#942)
1 parent d0a73ed commit 19ef126

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinWhenStringFilterTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,21 @@ public void should_filter() {
105105
assertIgnored(new Range(expectedFromInclusive, expectedToInclusive));
106106
}
107107

108+
@Test
109+
public void should_not_filter_empty_lookup_switch() {
110+
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0,
111+
"name", "(Ljava/lang/String;)V", null, null);
112+
m.visitVarInsn(Opcodes.ALOAD, 1);
113+
m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode",
114+
"()I", false);
115+
final Label defaultCase = new Label();
116+
m.visitLookupSwitchInsn(defaultCase, null, new Label[] {});
117+
m.visitLabel(defaultCase);
118+
m.visitInsn(Opcodes.RETURN);
119+
120+
filter.filter(m, context, output);
121+
122+
assertIgnored();
123+
}
124+
108125
}

org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinWhenStringFilter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public void match(final AbstractInsnNode start,
6767
hashCodes = tableSwitch.labels.size();
6868
}
6969

70+
if (hashCodes == 0) {
71+
return;
72+
}
73+
7074
final Set<AbstractInsnNode> replacements = new HashSet<AbstractInsnNode>();
7175
replacements.add(skipNonOpcodes(defaultLabel));
7276

org.jacoco.doc/docroot/doc/changes.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ <h3>Fixed bugs</h3>
4747
<li>To avoid failures with invalid class files report generation now checks
4848
that source references are actually files
4949
(GitHub <a href="https://github.com/jacoco/jacoco/issues/941">#941</a>).</li>
50+
<li><code>NullPointerException</code> during filtering
51+
(GitHub <a href="https://github.com/jacoco/jacoco/issues/942">#942</a>).</li>
5052
</ul>
5153

5254
<h3>Non-functional Changes</h3>

0 commit comments

Comments
 (0)