From d1ca5fa6cd03cdf3588e2ced1bf36e835511f3d3 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Sun, 22 Sep 2019 01:22:42 +0200 Subject: [PATCH 1/3] (WIP) add test --- .../filter/StringSwitchEcjFilterTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchEcjFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchEcjFilterTest.java index 3f726185bf..a13ea8f047 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchEcjFilterTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchEcjFilterTest.java @@ -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(); + } + } From 14dead119084e4d273487fa6ce1d3138990d7589 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Sun, 22 Sep 2019 01:35:51 +0200 Subject: [PATCH 2/3] (WIP) fix --- .../core/internal/analysis/filter/StringSwitchEcjFilter.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/StringSwitchEcjFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/StringSwitchEcjFilter.java index e0aba35d89..0e2c1e4d72 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/StringSwitchEcjFilter.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/StringSwitchEcjFilter.java @@ -70,6 +70,10 @@ public void match(final AbstractInsnNode start, final Set replacements = new HashSet(); replacements.add(skipNonOpcodes(defaultLabel)); + if (hashCodes == 0) { + return; + } + for (int i = 0; i < hashCodes; i++) { while (true) { nextIsVar(Opcodes.ALOAD, "s"); From 6f446fd961e01ff1a878682ba4787683977c05d6 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Sun, 22 Sep 2019 14:33:59 +0200 Subject: [PATCH 3/3] (WIP) update changelog --- org.jacoco.doc/docroot/doc/changes.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html index c1f5bf722c..6197c56d99 100644 --- a/org.jacoco.doc/docroot/doc/changes.html +++ b/org.jacoco.doc/docroot/doc/changes.html @@ -48,7 +48,8 @@

Fixed bugs

that source references are actually files (GitHub #941).
  • NullPointerException during filtering - (GitHub #942).
  • + (GitHub #942, + #944).

    Non-functional Changes