Java - can't see a variable in debugging without initialization until

Given the following method in Java in jdk6

public void test(){
Integer i;
try{
   i = 9;
} catch (Exception ex){
   //nothing
}
int something = 1; //Breakpoint here
}

When I stop at the breakpoint, I don’t see the variable “i” on the stack at all, although I see step by step that 9 was assigned to the try block.

public void test(){
Integer i = null;
try{
   i = 9;
} catch (Exception ex){
   //nothing
}
int something = 1; //Breakpoint here
}

Initialization of variable "i" to zero. I will see I = 9 when I get to the breakpoint.

I'm just wondering what's going on under the hood. I do not put the compiler on the stack in the first case, or the reason is related to the behavior of the JVM itself.

+4
source share
1 answer

, " " " " , . ( JVM, -. , .)

javap ( Java.class) :

  public void test();
descriptor: ()V
flags: ACC_PUBLIC
Code:
  stack=1, locals=3, args_size=1
     0: bipush        9
     2: invokestatic  #8                  // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     5: astore_1
     6: goto          10
     9: astore_2
    10: iconst_1
    11: istore_2
    12: return
  Exception table:
     from    to  target type
         0     6     9   Class java/lang/Exception
  LineNumberTable:
    line 27: 0
    line 30: 6
    line 28: 9
    line 31: 10
    line 32: 12
  LocalVariableTable:
    Start  Length  Slot  Name   Signature
       10       0     2    ex   Ljava/lang/Exception;
        0      13     0  this   LExample;
        6       3     1     i   Ljava/lang/Integer;
       12       1     2 something   I

( 31 ), 10 - ( LineNumberTable). LocalVariableTable , i 6 9, . , i , 1, ; , , . ( -/// .., - , - , . , , , .)

+1
source

Source: https://habr.com/ru/post/1524834/


All Articles