Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package org.jacoco.core.test.validation.kotlin.targets

import org.jacoco.core.test.validation.targets.Stubs.nop
import org.jacoco.core.test.validation.targets.Stubs.StubException
import org.jacoco.core.test.validation.targets.Stubs.ex

/**
* Test target for [safe call operator (`?.`)](https://kotlinlang.org/docs/null-safety.html#safe-call-operator).
Expand Down Expand Up @@ -76,11 +78,22 @@ object KotlinSafeCallOperatorTarget {
fullCoverage(A(B("")))
}

private fun safeCallChainException() {
fun example(a: A?): String? =
a?.also { ex() }?.b?.c // assertPartlyCovered(3, 1)

try {
example(A(B("")))
} catch (_: StubException) {
}
}

@JvmStatic
fun main(args: Array<String>) {
safeCall()
safeCallChain()
safeCallChainMultiline()
safeCallChainException()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void should_filter_optimized_safe_call_chain() {
assertIgnored(m);
final HashMap<AbstractInsnNode, List<Replacement>> replacements = new HashMap<AbstractInsnNode, List<Replacement>>();
replacements.put(ifNullInstruction1, Arrays.asList( //
new Replacement(0, ifNullInstruction2, 0),
new Replacement(0, ifNullInstruction1, 0),
new Replacement(1, popInstruction, 0)));
replacements.put(ifNullInstruction2, Arrays.asList( //
new Replacement(0, ifNullInstruction2, 0),
Expand Down Expand Up @@ -127,7 +127,7 @@ public void should_filter_unoptimized_safe_call_chain() {
assertIgnored(m);
final HashMap<AbstractInsnNode, List<Replacement>> replacements = new HashMap<AbstractInsnNode, List<Replacement>>();
replacements.put(ifNullInstruction1, Arrays.asList( //
new Replacement(0, ifNullInstruction2, 0),
new Replacement(0, ifNullInstruction1, 0),
new Replacement(1, aconstNullInstruction, 0)));
replacements.put(ifNullInstruction2, Arrays.asList( //
new Replacement(0, ifNullInstruction2, 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public void filter(final MethodNode methodNode,
.get(chain.size() - 1);
final AbstractInsnNode nullTarget = AbstractMatcher
.skipNonOpcodes(lastIfNullInstruction.label);
final Replacements replacements = new Replacements();
replacements.add(lastIfNullInstruction, lastIfNullInstruction, 0);
replacements.add(nullTarget, nullTarget, 0);
for (final AbstractInsnNode ifNullInstruction : chain) {
final Replacements replacements = new Replacements();
replacements.add(ifNullInstruction, ifNullInstruction, 0);
replacements.add(nullTarget, nullTarget, 0);
output.replaceBranches(ifNullInstruction, replacements);
}
}
Expand Down
2 changes: 2 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ <h3>Fixed bugs</h3>
<li>Fixed handling of implicit <code>default</code> clause of <code>switch</code>
by <code>String</code> in Java when compiled by ECJ
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1813">#1813</a>).</li>
<li>Fixed handling of exceptions in chains of safe call operators in Kotlin
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1819">#1819</a>).</li>
</ul>

<h2>Release 0.8.13 (2025/04/02)</h2>
Expand Down
Loading