Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
访问ASM Java库中的局部变量_Java_Variables_Local - Fatal编程技术网

访问ASM Java库中的局部变量

访问ASM Java库中的局部变量,java,variables,local,Java,Variables,Local,我试图在插入方法时调用局部变量。 到目前为止,我能够在节点中获取局部变量,但在实际访问任何内容时遇到困难 这是我的插入材料(非常零散,我已经做了一段时间,设计在一段时间前不再是我的主要优先事项): 它产生: Local Variable: one : Z : null : 0 Local Variable: two : Ljava/lang/String; : null : 1 added local var 'two' Local Variable: three : I : null : 2

我试图在插入方法时调用局部变量。 到目前为止,我能够在节点中获取局部变量,但在实际访问任何内容时遇到困难

这是我的插入材料(非常零散,我已经做了一段时间,设计在一段时间前不再是我的主要优先事项):

它产生:

Local Variable: one : Z : null : 0
Local Variable: two : Ljava/lang/String; : null : 1
added local var 'two'
Local Variable: three : I : null : 2
Exception in thread "main" java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    revel/reflection/test/SomeClass.testLocals(Z)V @0: aload_1
  Reason:
    Type top (current frame, locals[1]) is not assignable to reference type
  Current Frame:
    bci: @0
    flags: { }
    locals: { integer }
    stack: { }
  Bytecode:
    0000000: 2bb8 0040 1242 4c04 3b10 403d b12b     

        at revel.reflection.test.Test.main(Test.java:66)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at                         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
第66行是SomeClass.testLocals(true);
有人能解释一下情况吗?

看来你的问题出在指令行
mn.insert(list)
在方法的所有指令列表的开头插入新指令
testLocals
。换句话说,在变量
two
被声明或赋值之前,您已经使用了它。尝试使用
mn.instructions.add(列表)并查看这是否解决不了问题


祝你好运

这正是问题所在。真不敢相信我居然没想到。谢谢
    public static void testLocals(boolean one) {
    String two = "hello local variables";
    one = true;
    int three = 64;
}
Local Variable: one : Z : null : 0
Local Variable: two : Ljava/lang/String; : null : 1
added local var 'two'
Local Variable: three : I : null : 2
Exception in thread "main" java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    revel/reflection/test/SomeClass.testLocals(Z)V @0: aload_1
  Reason:
    Type top (current frame, locals[1]) is not assignable to reference type
  Current Frame:
    bci: @0
    flags: { }
    locals: { integer }
    stack: { }
  Bytecode:
    0000000: 2bb8 0040 1242 4c04 3b10 403d b12b     

        at revel.reflection.test.Test.main(Test.java:66)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at                         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)