No line number table entry seems to be generated for the implicit return instruction at the end of a void method. This can result in very confusing behavior for debugger users. For example,
public class Bug1 {
public static void main(String args[]) {
if (args.length == 0) {
System.out.println("No arguments");
} else {
System.out.println(args.length + " arguments");
}
}
}
From the javap output below, the return statement ends up as part of the second println's line. After stepping through the if-clause, debugger users next land on the println in the else clause.
This bug is similar, but actually worse than, bug 4026577 reported against the old javac.
H:\work>javap -c -l Bug1
Compiled from Bug1.java
public class Bug1 extends java.lang.Object {
public Bug1();
public static void main(java.lang.String[]);
}
Method Bug1()
0 aload_0
1 invokespecial #1 <Method java.lang.Object()>
4 return
Line numbers for method Bug1()
line 1: 0
Local variables for method Bug1()
Bug1 this pc=0, length=5, slot=0
Method void main(java.lang.String[])
0 aload_0
1 arraylength
2 iconst_0
3 if_icmpne 17
6 getstatic #2 <Field java.io.PrintStream out>
9 ldc #3 <String "No arguments">
11 invokevirtual #4 <Method void println(java.lang.String)>
14 goto 43
17 getstatic #2 <Field java.io.PrintStream out>
20 new #5 <Class java.lang.StringBuffer>
23 dup
24 invokespecial #6 <Method java.lang.StringBuffer()>
27 aload_0
28 arraylength
29 invokevirtual #7 <Method java.lang.StringBuffer append(int)>
32 ldc #8 <String " arguments">
34 invokevirtual #9 <Method java.lang.StringBuffer append(java.lang.String)>
37 invokevirtual #10 <Method java.lang.String toString()>
40 invokevirtual #4 <Method void println(java.lang.String)>
43 return
Line numbers for method void main(java.lang.String[])
line 3: 0
line 4: 6
line 6: 17
Local variables for method void main(java.lang.String[])
java.lang.String[] args pc=0, length=44, slot=0
public class Bug1 {
public static void main(String args[]) {
if (args.length == 0) {
System.out.println("No arguments");
} else {
System.out.println(args.length + " arguments");
}
}
}
From the javap output below, the return statement ends up as part of the second println's line. After stepping through the if-clause, debugger users next land on the println in the else clause.
This bug is similar, but actually worse than, bug 4026577 reported against the old javac.
H:\work>javap -c -l Bug1
Compiled from Bug1.java
public class Bug1 extends java.lang.Object {
public Bug1();
public static void main(java.lang.String[]);
}
Method Bug1()
0 aload_0
1 invokespecial #1 <Method java.lang.Object()>
4 return
Line numbers for method Bug1()
line 1: 0
Local variables for method Bug1()
Bug1 this pc=0, length=5, slot=0
Method void main(java.lang.String[])
0 aload_0
1 arraylength
2 iconst_0
3 if_icmpne 17
6 getstatic #2 <Field java.io.PrintStream out>
9 ldc #3 <String "No arguments">
11 invokevirtual #4 <Method void println(java.lang.String)>
14 goto 43
17 getstatic #2 <Field java.io.PrintStream out>
20 new #5 <Class java.lang.StringBuffer>
23 dup
24 invokespecial #6 <Method java.lang.StringBuffer()>
27 aload_0
28 arraylength
29 invokevirtual #7 <Method java.lang.StringBuffer append(int)>
32 ldc #8 <String " arguments">
34 invokevirtual #9 <Method java.lang.StringBuffer append(java.lang.String)>
37 invokevirtual #10 <Method java.lang.String toString()>
40 invokevirtual #4 <Method void println(java.lang.String)>
43 return
Line numbers for method void main(java.lang.String[])
line 3: 0
line 4: 6
line 6: 17
Local variables for method void main(java.lang.String[])
java.lang.String[] args pc=0, length=44, slot=0
- duplicates
-
JDK-4243913 Regression: line number for the method declaration is not
-
- Closed
-
- relates to
-
JDK-4304479 java compiler generates inaccurate LineNumberTable attribute
-
- Resolved
-
-
JDK-4026577 line numbers for first lines of functions are wrong
-
- Closed
-
-
JDK-4256607 Regression failure in debugger: Wrong executeble locations are returned.
-
- Closed
-