diff options
author | Evgeny Mandrikov <138671+Godin@users.noreply.github.com> | 2019-09-22 09:16:51 +0200 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2019-09-22 09:16:51 +0200 |
commit | 19ef126cf9f3d57bd7a6a147ef745531c751422a (patch) | |
tree | 83995056a7ec6e355350216f68f1f510c3745e10 | |
parent | d0a73edd41a29f4c0ffabae15d7c023a37df976f (diff) | |
download | jacoco-19ef126cf9f3d57bd7a6a147ef745531c751422a.tar.gz |
Fix NPE in KotlinWhenStringFilter (#942)
3 files changed, 23 insertions, 0 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinWhenStringFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinWhenStringFilterTest.java index df42803d..4408ef3d 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinWhenStringFilterTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinWhenStringFilterTest.java @@ -105,4 +105,21 @@ public class KotlinWhenStringFilterTest extends FilterTestBase { 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(); + } + } diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinWhenStringFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinWhenStringFilter.java index fcccb550..864473f2 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinWhenStringFilter.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinWhenStringFilter.java @@ -67,6 +67,10 @@ public final class KotlinWhenStringFilter implements IFilter { hashCodes = tableSwitch.labels.size(); } + if (hashCodes == 0) { + return; + } + final Set<AbstractInsnNode> replacements = new HashSet<AbstractInsnNode>(); replacements.add(skipNonOpcodes(defaultLabel)); diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html index 82042ad0..c1f5bf72 100644 --- a/org.jacoco.doc/docroot/doc/changes.html +++ b/org.jacoco.doc/docroot/doc/changes.html @@ -47,6 +47,8 @@ <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> |