-
-
Notifications
You must be signed in to change notification settings - Fork 829
Open
Labels
Description
jvm runtime: openjdk17
bytebudy version: 1.14.3
i tried to interrupt " java.time.Clock#instant" method with below code, but it did not work?
new AgentBuilder.Default()
.disableClassFormatChanges()
.ignore(nameStartsWith("net.bytebuddy."))
.with(new TransformListener())
.with(new ByteBuddy().with(Implementation.Context.Disabled.Factory.INSTANCE))
.with(AgentBuilder.InitializationStrategy.NoOp.INSTANCE)
.with(AgentBuilder.RedefinitionStrategy.REDEFINITION)
.with(AgentBuilder.TypeStrategy.Default.REDEFINE)
.type(hasSuperClass(ElementMatchers.named("java.time.Clock")))
.transform((builder, typeDescription, classLoader, module, protectionDomain) -> builder
.method(ElementMatchers.named("instant"))
.intercept(Advice.to(ClockInterceptor.class).wrap(StubMethod.INSTANCE)))
.installOn(inst);
ClockInterceptor code is:
@Slf4j
public class ClockInterceptor {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void onExit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Instant result) {
if (ClockMockDispatcher.dispatcher != null) {
long mockMillis = ClockMockDispatcher.dispatcher.mockMillis();
if (mockMillis > 0) {
result = Instant.ofEpochMilli(mockMillis);
}
}
}
}