JDK-4419723 : Line number information for try-catch statement is not sufficient
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.3.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2001-02-28
  • Updated: 2001-12-03
  • Resolved: 2001-03-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other
1.3.1_03 03Fixed 1.4.0Fixed
Related Reports
Relates :  
Description
Line number information generated for a try-catch statement is not
sufficient for debugger to show more reasonable single-stepping information.

     1  import java.io.*;
     2
     3  public class HelloWorld {
     4    public static void main(String[] args) {
     5      int i = 10;
     6      System.out.println("Hello World!");
     7      try {
     8        if ((i % 2) == 0) {
     9          System.out.println("i = " + i + " is an even number.");
    10          Integer.parseInt("200");
    11        } else {
    12          System.out.println("i = " + i + " is an odd number.");
    13          Thread.sleep(10);
    14        }
    15      } catch (Exception e) {
    16          System.out.println("Exception caught!");
    17      }
    18
    19      System.out.println("Bye");
    20    }
    21  }
> /usr/local/java/jdk1.3.1/solsparc/bin/java -version
java version "1.3.1-rc1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-rc1-b17)
Java HotSpot(TM) Client VM (build 1.3.1rc1-b17, mixed mode)

When I debug this program using jdb, and stop at line 10 and then do a 'step',
it shows line 13, which is really confusing because line 13 is *not* executed at all. 

Using javap to show the bytecode and line table information:
> /usr/local/java/jdk1.3.1/solsparc/bin/javap -l -c HelloWorld
Compiled from HelloWorld.java
public class HelloWorld extends java.lang.Object {
    public HelloWorld();
    public static void main(java.lang.String[]);
}

Method HelloWorld()
   0 aload_0
   1 invokespecial #1 <Method java.lang.Object()>
   4 return

Line numbers for method HelloWorld()
   line 3: 0

Local variables for method HelloWorld()
   HelloWorld this  pc=0, length=5, slot=0

Method void main(java.lang.String[])
   0 bipush 10
   2 istore_1
   3 getstatic #2 <Field java.io.PrintStream out>
   6 ldc #3 <String "Hello World!">
   8 invokevirtual #4 <Method void println(java.lang.String)>
  11 iload_1
  12 iconst_2
  13 irem
  14 ifne 56
  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 ldc #7 <String "i = ">
  29 invokevirtual #8 <Method java.lang.StringBuffer append(java.lang.String)>
  32 iload_1
  33 invokevirtual #9 <Method java.lang.StringBuffer append(int)>
  36 ldc #10 <String " is an even number.">
  38 invokevirtual #8 <Method java.lang.StringBuffer append(java.lang.String)>
  41 invokevirtual #11 <Method java.lang.String toString()>
  44 invokevirtual #4 <Method void println(java.lang.String)>
  47 ldc #12 <String "200">
  49 invokestatic #13 <Method int parseInt(java.lang.String)>
  52 pop
  53 goto 92
  56 getstatic #2 <Field java.io.PrintStream out>
  59 new #5 <Class java.lang.StringBuffer>
  62 dup
  63 invokespecial #6 <Method java.lang.StringBuffer()>
  66 ldc #7 <String "i = ">
  68 invokevirtual #8 <Method java.lang.StringBuffer append(java.lang.String)>
  71 iload_1
  72 invokevirtual #9 <Method java.lang.StringBuffer append(int)>
  75 ldc #14 <String " is an odd number.">
  77 invokevirtual #8 <Method java.lang.StringBuffer append(java.lang.String)>
  80 invokevirtual #11 <Method java.lang.String toString()>
  83 invokevirtual #4 <Method void println(java.lang.String)>
  86 ldc2_w #15 <Long 10>
  89 invokestatic #17 <Method void sleep(long)>
  92 goto 104
  95 astore_2
  96 getstatic #2 <Field java.io.PrintStream out>
  99 ldc #19 <String "Exception caught!">
 101 invokevirtual #4 <Method void println(java.lang.String)>
 104 getstatic #2 <Field java.io.PrintStream out>
 107 ldc #20 <String "Bye">
 109 invokevirtual #4 <Method void println(java.lang.String)>
 112 return
Exception table:
   from   to  target type
    11    92    95   <Class java.lang.Exception>

Line numbers for method void main(java.lang.String[])
   line 5: 0
   line 6: 3
   line 8: 11
   line 9: 17
   line 10: 47
   line 12: 56
   line 13: 86
   line 16: 95
   line 19: 104
   line 20: 112

Local variables for method void main(java.lang.String[])
   java.lang.String[] args  pc=0, length=113, slot=0
   int i  pc=3, length=109, slot=1
   java.lang.Exception e  pc=95, length=9, slot=2

After executing line 10, bci will be at 92 goto 104, which does not 
associate with any line number.  So jdb chooses to show line 13, which
is the last line that has bci <= 92.

Request to generate additional line table information to indicate 
appropriate line associated with a catch statement.  E.g. bci 92 of
HelloWorld.main refers to line 15.
 

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.3.1_03 merlin-beta FIXED IN: 1.3.1_03 merlin-beta INTEGRATED IN: 1.3.1_03 merlin-beta VERIFIED IN: merlin-beta3
14-06-2004

PUBLIC COMMENTS .
10-06-2004

EVALUATION Requires some parse tree changes (source position for the close curly brace on blocks). There is a systematic problem where this can happen in many places where we generate control- flow bookkeeping code. neal.gafter@Eng 2001-03-01
01-03-2001