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

Empty try/finally results in bytecodes being generated

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P5
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: 8
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b82
    • CPU:
      x86
    • OS:
      linux_redhat_9.0
    • Verification:
      Verified

      Description

      A try/finally with nothing in the finally results in additional byte codes being generated.

      Here's the test case:
      import java.awt.*;
      import java.awt.event.*;
      import java.awt.image.*;
      import java.io.File;
      import javax.swing.*;
      import javax.swing.filechooser.*;

      public class Test {
          public static void main(String[] args) {
              JComponent x = new JComponent() {
                  public boolean isShowing() {
                      return true;
                  }
                  public boolean isOpaque() {
                      return true;
                  }
              };
              // try {
              x.setSize(200, 200);
              x.paintImmediately(0, 0, 200, 200);
              System.out.println("DONE!");
              // } finally {}
          }
      }

      Here's the output from javap as is:
      Compiled from "Test.java"
      public class Test extends java.lang.Object{
      public Test();
        Code:
         0:aload_0
         1:invokespecial#1; //Method java/lang/Object."<init>":()V
         4:return

      public static void main(java.lang.String[]);
        Code:
         0:new#2; //class Test$1
         3:dup
         4:invokespecial#3; //Method Test$1."<init>":()V
         7:astore_1
         8:aload_1
         9:sipush200
         12:sipush200
         15:invokevirtual#4; //Method javax/swing/JComponent.setSize:(II)V
         18:aload_1
         19:iconst_0
         20:iconst_0
         21:sipush200
         24:sipush200
         27:invokevirtual#5; //Method javax/swing/JComponent.paintImmediately:(IIII)V
         30:getstatic#6; //Field java/lang/System.out:Ljava/io/PrintStream;
         33:ldc#7; //String DONE!
         35:invokevirtual#8; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
         38:return

      }

      And when you uncomment the try/finally here's the output:
      Compiled from "Test.java"
      public class Test extends java.lang.Object{
      public Test();
        Code:
         0:aload_0
         1:invokespecial#1; //Method java/lang/Object."<init>":()V
         4:return

      public static void main(java.lang.String[]);
        Code:
         0:new#2; //class Test$1
         3:dup
         4:invokespecial#3; //Method Test$1."<init>":()V
         7:astore_1
         8:aload_1
         9:sipush200
         12:sipush200
         15:invokevirtual#4; //Method javax/swing/JComponent.setSize:(II)V
         18:aload_1
         19:iconst_0
         20:iconst_0
         21:sipush200
         24:sipush200
         27:invokevirtual#5; //Method javax/swing/JComponent.paintImmediately:(IIII)V
         30:getstatic#6; //Field java/lang/System.out:Ljava/io/PrintStream;
         33:ldc#7; //String DONE!
         35:invokevirtual#8; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
         38:goto44
         41:astore_2
         42:aload_2
         43:athrow
         44:return
        Exception table:
         from to target type
           8 38 41 any
          41 42 41 any

      }


      I'm not sure if this intentional for debugging purposes, hence filing as an RFE.
      ###@###.### 10/20/04 15:20 GMT

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vromero Vicente Arturo Romero Zaldivar
                Reporter:
                svioletsunw Scott Violet (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: