gpt4 book ai didi

javassist.CannotCompileException : [source error] ) is missing what is this?

转载 作者:行者123 更新时间:2023-11-30 03:19:40 24 4
gpt4 key购买 nike

我现在正在尝试在我的网络应用程序中编写一些字节码操作,当我尝试将代码注入(inject)到我的方法中时,它总是会抛出错误

javassist.CannotCompileException: [source error] ) is missing

我不知道为什么以及这是什么......我用谷歌搜索了一下,有些人说这是 1.0 javassist 版本的错误,但我认为这真的不现实。

  private void changeMethod(CtMethod method) throws NotFoundException, 
CannotCompileException {
if (method.hasAnnotation(Loggable.class)) {

method.getName();


method.insertBefore("long startTime = 0;" +
"long startTime = System.currentTimeMillis();" +
" Thread thread1 = new Thread(new Runnable(){\n" +
" @Override\n" +
" public void run() {\n" +
" threadLogger.info(\"Testlog\");\n" +
"\n" +
" try {\n" +
" threadLogger.logCall(Webservice.this.getClass().getMethod(startThread0), \"Thread\");\n" +
" \n" +
" } catch (Exception e) {\n" +
" e.printStackTrace();\n" +
" }\n" +
"\n" +
" }\n" +
" });\n" +
" thread1.start();");

}
}
enter code here

最佳答案

正如您在 Javassist 文档中所读到的那样,section 4.7 Limitations (粗体是我的):

Inner classes or anonymous classes are not supported. Note that this is a limitation of the compiler only. It cannot compile source code including an anonymous-class declaration. Javassist can read and modify a class file of inner/anonymous class.

您正在尝试注入(inject)匿名 Runnable 类,因此它不起作用。解决此问题的最佳方法是将 Runnable 类代码提取到注入(inject)和运行时类路径中可用的新类,并在注入(inject)代码中使用该类。

关于javassist.CannotCompileException : [source error] ) is missing what is this?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31649970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com