Closed jiangyunpeng closed 8 months ago
ChatGTP is pretty much correct. There's no need to limit the scope here as the assignment can never yield an exception. I assume that it's a simple simplification.
Thanks a lot for the detailed response.
Actually, i used ByteBuddy and asm to develop a online debug tools.
I decompile user's class to java source code, and user can debug at any source code line. We will record every variable before user debug code line . for example below code ,if user debug at L15, we will record the value of 'a' and 'b' variables.
L11 public void sum2() {
L12 int a = 25;
L13 try {
L14 int b = 8;
L15 if (a > 20) {
L16 int k = a + b;
L17 System.out.println("k=" + k);
L18 }
L19 } catch (Exception e) {
L20 e.printStackTrace();
L21 }
L22 }
But if user debug at L20. we will generate error bytecode base ' LocalVariableTable ' , Because our bytecode will try to record variable 'b' at catch statement but actually it can't be accessed.
So could you give some advice to me for this case?
i think may be need parse source code manually for resolve this case
I would argue that it would be possible to access the value using the Java debugger.
Thanks , Have a nice day.
I am sorry, this is a question about java Bytecode not about byteBuddy, because i couldn't find a appropriate place to post. and i know the Rafael Winterhalter is a nice guy. so i post here🙇 .
This question is about LocalVariableTable scope.
I write a simple code:
I think the scope of variable
b
must be in the try statement, which is line 15~18.But actually, when i use javap generate bytecode :
The scope of variable
b
is line 15~21? (start=6,end=41) ,Why? It is obvious,the variable b can't be accessed in the catch statement.i asked chatGPT, it said:
but i can't confirm it if correct, because i don't find any references describe it