Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4665839

incorrect local variable attribute generated by javac

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 1.4.2
    • 1.4.0
    • tools
    • mantis
    • x86
    • windows_2000

    Description



      Name: nt126004 Date: 04/10/2002


      FULL PRODUCT VERSION :
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      FULL OPERATING SYSTEM VERSION :

      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      Javac is generating the incorrect pc value for variables
      declared in catch statements (i.e. catch(Exception myEVar)

      So code that looks like:

      try
      {
      }
      catch(Exception e)
      {
         System.out.println(e.toString())
      }

      when in a debugger such as jdb and at a breakpoint on the
      system.out.println line, e will not show up in the local
      variables list... See sample below for sample source and
      javap output showing problem...



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the simple HelloWorld.java source provided for
      debug using javac.

      Now load resulting class into jdb and follow this session:

      D:\test_projects\helloWorld>java -version
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build
      1.4.0-b
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      D:\test_projects\helloWorld>jdb HelloWorld
      Initializing jdb ...
      > stop at HelloWorld:16
      Deferring breakpoint HelloWorld:16.
      It will be set after the class is loaded.
      > run
      run HelloWorld
      >
      VM Started: Set deferred breakpoint HelloWorld:16
      Hello World!
      i = 10 is an even number.

      Breakpoint hit: "thread=main", HelloWorld.main(), line=16
      bci=9
      16 System.out.println("Exception caught!" + e);

      main[1] locals
      Method arguments:
      args = instance of java.lang.String[0] (id=287)
      Local variables:
      i = 10
      main[1]



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      When I printed local variables for my sample in jdb, it
      only showed the my local int i and the args to main. It
      should have also listed e...

      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      HelloWorld.java:

      import java.io.*;

      public class HelloWorld {
         public static void main(String[] args) {
           int i = 10;
           System.out.println("Hello World!");
           try {
             if ((i % 2) == 0) {
               System.out.println("i = " + i + " is an even number.");
               Integer.parseInt("zzz200");
             } else {
               System.out.println("i = " + i + " is an odd number.");
               Thread.sleep(10);
             }
           } catch (Exception e) {
               System.out.println("Exception caught!" + e);
           }

           System.out.println("Bye");
         }
      }


      javap dump showing incorrect local var table generated for e:

      D:\test_projects\helloWorld>javap -c -l 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 "zzz200">
        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 121
        95 astore_2
        96 getstatic #2 <Field java.io.PrintStream out>
        99 new #5 <Class java.lang.StringBuffer>
       102 dup
       103 invokespecial #6 <Method java.lang.StringBuffer()>
       106 ldc #19 <String "Exception caught!">
       108 invokevirtual #8 <Method java.lang.StringBuffer append(java.lang.String)
       111 aload_2
       112 invokevirtual #20 <Method java.lang.StringBuffer append(java.lang.Object
       115 invokevirtual #11 <Method java.lang.String toString()>
       118 invokevirtual #4 <Method void println(java.lang.String)>
       121 getstatic #2 <Field java.io.PrintStream out>
       124 ldc #21 <String "Bye">
       126 invokevirtual #4 <Method void println(java.lang.String)>
       129 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 15: 92
         line 16: 95
         line 19: 121
         line 20: 129

      Local variables for method void main(java.lang.String[])
         java.lang.String[] args pc=0, length=130, slot=0
         int i pc=3, length=126, slot=1
         java.lang.Exception e pc=96, length=25, slot=2

      NOTE : pc should have been 95 not 96 in the above table for e...



      ---------- END SOURCE ----------
      (Review ID: 144945)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              gafter Neal Gafter
              nthompsosunw Nathanael Thompson (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: