- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我现在正在尝试在我的网络应用程序中编写一些字节码操作,当我尝试将代码注入(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/
我正在尝试通过javassist调用java.util.Arrays.asList(..)。但是得到下面的异常。 javassist.CannotCompileException: [source e
嗯尝试检测一种方法来完成以下任务。 任务 - 创建映射并将值插入到映射中添加 System.out.println 行不会导致任何异常。但是,当我添加行来创建 map 时,由于缺少;,它会抛出cann
我现在正在尝试在我的网络应用程序中编写一些字节码操作,当我尝试将代码注入(inject)到我的方法中时,它总是会抛出错误 javassist.CannotCompileException: [sour
我正在尝试使用 javassist 来将 System.out.println 添加到现有类的方法中,使用此代码 - .... ClassPool pool = new ClassPool();
我正在使用 Java 工具和 Javassist将 print 语句插入方法中。这大多数情况下都不会出现错误,但对于某些类方法(例如 java.util.TimeZone.getSystemTimeZ
我正在尝试使用字节码检测添加 try catch block 。 基本上,我有一个“Lion”类。我想在 try block 中捕获其方法“stayLion()”之一的全部内容并给出相应的 catch
引用:http://jboss-javassist.github.io/javassist/tutorial/tutorial2.html method.insertBefore("{ System.
我正在执行以下操作并获得奖励: Exception in thread "main" java.lang.NoClassDefFoundError: javassist/CannotCompi
我正在使用 javassist 来更改方法体。当该方法在应用程序中定义时我可以做到这一点。但是,当我想更改应用程序使用的 jar 文件中定义的方法时,我会收到以下运行时错误: javassist.Ca
我是一名优秀的程序员,十分优秀!