Is it possible to rebase System.currentTimeMillis
See original GitHub issueHi,
I’ve spent a long time trying to figure out how to rebase System.currentTimeMillis. What I wanted is override this bootstrap class’s method with another customized clock, which means I still need to call the original System.currentTimeMillis to get the actual time and have some transformation on it. I have already successfully redefine the method with following code on Java agent mode:-
final ByteBuddy byteBuddy = new ByteBuddy().with(Implementation.Context.Disabled.Factory.INSTANCE);
new AgentBuilder.Default()
.enableNativeMethodPrefix("test_native")
.with(byteBuddy)
.with(AgentBuilder.InitializationStrategy.NoOp.INSTANCE)
.with(AgentBuilder.RedefinitionStrategy.REDEFINITION)
.with(AgentBuilder.TypeStrategy.Default.REDEFINE)
.ignore(none())
.type(ElementMatchers.named("java.lang.System"))
.transform(new AgentBuilder.Transformer() {
@Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) {
return builder.method(ElementMatchers.named("currentTimeMillis")).intercept(
MethodDelegation.to(SystemTimeInterceptor.class));
}
}).installOn(inst);
Can you please kindly advise if it is ever possible to rebase that method? Any suggestion will be appreciated. Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Redefine/Rebase native method - java - Stack Overflow
After trying with different combinations I finally get it works now. Actually the above code is correct. I think the possible reason not...
Read more >[#CASSANDRA-14092] Max ttl of 20 years will overflow ...
It turns out that next year the localDeletionTime will start overflowing with the maximum ttl of 20 years (System.currentTimeMillis() + ...
Read more >org.apache.jackrabbit.mk.model.StagedNodeTree.reset java code ...
public Id rebase(Id baseId, Id fromId, Id toId, PutToken token) throws Exception { // reset staging area to new base revision reset(baseId); StoredNode ......
Read more >Repository xref - Eclipse archive
46 */ 47 48 package org.eclipse.jgit.lib; 49 50 import java.io.BufferedOutputStream; 51 import java.io. ... 105 * <p> 106 * This class is thread-safe....
Read more >How to Git rebase master onto any branch by example
If other developers are currently working on branches that stem from those deleted commits, they will not be able to push their changes...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Just ran into the same problem, put my solution here, hoping to help others. If you need redefine
System. currentTimeMillis(), there is another way to get the real time.My solution is to call nanoTime and currentTimeMillis once each before injecting and save the result, so that the current time can be calculated using
, and then use ntp synchronized time to calculate the offset and change the savedCurrentTimeMillis value.