Skip to content

Commit 9bad366

Browse files
committed
post-review changes
1 parent 6f01994 commit 9bad366

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

javaagent-tooling/src/testExceptionHandler/java/io/opentelemetry/javaagent/tooling/bytebuddy/BadAdvice.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55

66
package io.opentelemetry.javaagent.tooling.bytebuddy;
77

8+
import java.util.concurrent.atomic.AtomicBoolean;
89
import net.bytebuddy.asm.Advice;
910

1011
@SuppressWarnings("unused")
1112
public class BadAdvice {
1213

1314
@Advice.OnMethodExit(suppress = Throwable.class)
14-
public static boolean throwAnException() {
15+
public static boolean throwAnException(@Advice.Argument(0) AtomicBoolean isInstrumented) {
16+
// mark that the advice has been executed
17+
isInstrumented.set(true);
1518
throw new IllegalStateException("Test Exception");
1619
}
1720

javaagent-tooling/src/testExceptionHandler/java/io/opentelemetry/javaagent/tooling/bytebuddy/ExceptionHandlerTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.opentelemetry.javaagent.bootstrap.ExceptionLogger;
1616
import java.net.URL;
1717
import java.net.URLClassLoader;
18+
import java.util.concurrent.atomic.AtomicBoolean;
1819
import java.util.logging.Level;
1920
import java.util.logging.Logger;
2021
import net.bytebuddy.agent.ByteBuddyAgent;
@@ -85,9 +86,9 @@ void exceptionHandlerInvoked() {
8586
int initLogEvents = testHandler.getRecords().size();
8687

8788
// Triggers classload and instrumentation
88-
assertThat(SomeClass.isInstrumented())
89-
.describedAs("method return value should be preserved when exception is thrown in advice")
90-
.isFalse();
89+
AtomicBoolean isInstrumented = new AtomicBoolean(false);
90+
SomeClass.isInstrumented(isInstrumented);
91+
assertThat(isInstrumented.get()).describedAs("method should have been instrumented").isTrue();
9192

9293
assertThat(testHandler.getRecords())
9394
.hasSize(initLogEvents + 1)
@@ -128,8 +129,8 @@ void exceptionHandlerSetsCorrectStackSize() {
128129

129130
public static class SomeClass {
130131

131-
public static boolean isInstrumented() {
132-
return false;
132+
public static void isInstrumented(AtomicBoolean instrumented) {
133+
instrumented.set(false);
133134
}
134135

135136
public static void smallStack() {

0 commit comments

Comments
 (0)