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

LineNumberTable wrong if enhanced-for-loops are used

    Details

    • Subcomponent:
    • Resolved In Build:
      b51
    • CPU:
      x86
    • OS:
      windows_vista
    • Verification:
      Not verified

      Description

      Here is the small program
      public class Main {

         /**
          * @param args the command line arguments
          */
         public static void main(String[] args) {
             Vector<Integer> ids = new Vector<Integer>() {
                 {
                     addElement(0);
                 }
             };
             int id = 0;
      // for(int currentId : ids){ // (A)
              for(int i = 0; i < ids.size(); i++) { // (B)
              int currentId = ids.elementAt(i); // (B)
                 if(id != currentId){
                     ids.insertElementAt(new Integer(id), id);
                     System.out.println("damn");
                 }
             }

         }

      }

      I tried to debug this in Netbeans 6.5. If I step through the code using old-style for loop (B) the stepping works as expected.
      If I use the enhanced-for loop (A), then the stepping stops at "damn" statement. Ofcourse it is not executing that statement. I guess it suppose to be hitting the closing brace after "damn".
      Looks like the generated code has some wrong line number table, that is why this problem.

      I used javap to get the Linenumber table attribute and it really seems to be wrong.
      Main.java and Main.javap are attached.

        Attachments

          Activity

            People

            • Assignee:
              mcimadamore Maurizio Cimadamore
              Reporter:
              anelatur Anki Nelaturu
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: