Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in StringSwitchEcjFilter #944

Merged
merged 4 commits into from Sep 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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