java.lang.System.currentTimeMillis() replace method

前端 未结 4 1493
-上瘾入骨i
-上瘾入骨i 2020-11-30 11:33

Aside from recompiling rt.jar is there any way I can replace the currentTimeMillis() call with one of my own?

1# The right way to

4条回答
  •  春和景丽
    2020-11-30 11:38

    You could use an AspectJ compiler/weaver to compile/weave the problematic user code, replacing the calls to java.lang.System.currentTimeMillis() with your own code. The following aspect will just do that:

    public aspect CurrentTimeInMillisMethodCallChanger {
    
        long around(): 
           call(public static native long java.lang.System.currentTimeMillis()) 
           && within(user.code.base.pckg.*) {
             return 0; //provide your own implementation returning a long
        }
    }
    

提交回复
热议问题