diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchJavacFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchJavacFilterTest.java
index 8b47302f20..16fac404c2 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchJavacFilterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchJavacFilterTest.java
@@ -115,6 +115,57 @@ public void should_filter_when_javac_generates_lookupswitch() {
assertIgnored(new Range(expectedFromInclusive, expectedToInclusive));
}
+ /**
+ *
+ */
+ @Test
+ public void should_not_filter_when_no_expected_goto() {
+ m.visitInsn(Opcodes.ICONST_M1);
+ m.visitVarInsn(Opcodes.ISTORE, 2);
+
+ m.visitVarInsn(Opcodes.ALOAD, 1);
+ m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode",
+ "()I", false);
+
+ final Label secondSwitch = new Label();
+ final Label h1 = new Label();
+ m.visitTableSwitchInsn(0, 0, secondSwitch, h1);
+
+ m.visitLabel(h1);
+ m.visitVarInsn(Opcodes.ALOAD, 1);
+ m.visitLdcInsn("");
+ m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
+ "(Ljava/lang/Object;)Z", false);
+ m.visitJumpInsn(Opcodes.IFEQ, secondSwitch);
+ m.visitInsn(Opcodes.ICONST_0);
+ m.visitVarInsn(Opcodes.ISTORE, 2);
+
+ // Something different from the expected by filter
+ // secondSwitch label or GOTO:
+ m.visitInsn(Opcodes.RETURN);
+
+ m.visitLabel(secondSwitch);
+ m.visitVarInsn(Opcodes.ILOAD, 2);
+ final Label defaultCase = new Label();
+ m.visitLookupSwitchInsn(defaultCase, new int[] {}, new Label[] {});
+ m.visitLabel(defaultCase);
+
+ filter.filter(m, context, output);
+
+ assertIgnored();
+ }
+
@Test
public void should_not_filter_code_generated_by_ECJ() {
final Label h1 = new Label();
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/StringSwitchJavacFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/StringSwitchJavacFilter.java
index a5baf34caa..7911cd1b23 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/StringSwitchJavacFilter.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/StringSwitchJavacFilter.java
@@ -87,6 +87,9 @@ boolean match(final AbstractInsnNode start,
break;
}
nextIs(Opcodes.GOTO);
+ if (cursor == null) {
+ return false;
+ }
if (((JumpInsnNode) cursor).label != secondSwitchLabel) {
return false;
}
diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html
index 7d1fe06ea0..c616997315 100644
--- a/org.jacoco.doc/docroot/doc/changes.html
+++ b/org.jacoco.doc/docroot/doc/changes.html
@@ -20,6 +20,12 @@
+ * int c = -1;
+ * switch (s.hashCode()) {
+ * case 0:
+ * if (s.equals(""))
+ * c = 0;
+ * return;
+ * default:
+ * }
+ * switch (c)
+ * // ...
+ *
NullPointerException
during filtering
+ (GitHub #1189).